Rabu, 13 Agustus 2025

JAVA - Grid Layout

 




/*

 * To change this license header, choose License Headers in Project Properties.

 * To change this template file, choose Tools | Templates

 * and open the template in the editor.

 */

package tgridlayout;

import javax.swing.*;

import java.awt.*;


public class TGridLayout extends JApplet {

    Container container = null;


    public void init() {

       // 1. Get a handle on the applet's content pane.

       container = this.getContentPane();


       // 2. Assign the grid layout to the content pane.

       GridLayout grid = new GridLayout(3,2, 5,5);

           // rows = 3, cols = 2, horizontal gap =5, vertical gap = 5

       container.setLayout(grid);


       // 3. Create and add components to the content pane.

       for (int i=0; i<6; i++)

          container.add(new JButton("Button"+(i+1)));

    }

}


Tidak ada komentar: