0% found this document useful (0 votes)
40 views1 page

007 GridLayout

This document discusses using a GridLayout layout manager in Java. It creates a 3x3 grid of buttons using GridLayout and adds them to a JFrame. GridLayout places components into a grid of equal-sized cells, with each component taking up the whole cell. The example creates 9 buttons, labels them 1-9, and adds them to a JFrame with a 3x3 GridLayout, displaying them in a 3x3 grid.

Uploaded by

Momed Groove
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

007 GridLayout

This document discusses using a GridLayout layout manager in Java. It creates a 3x3 grid of buttons using GridLayout and adds them to a JFrame. GridLayout places components into a grid of equal-sized cells, with each component taking up the whole cell. The example creates 9 buttons, labels them 1-9, and adds them to a JFrame with a 3x3 GridLayout, displaying them in a 3x3 grid.

Uploaded by

Momed Groove
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

7 – GridLayout

import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Main


{

public static void main(String[] args)


{

// Layout Manager = Defines the natural layout for components within a container

// GridLayout = places components in a grid of cells.


// Each component takes all the available space within its cell,
// and each cell is the same size.

JFrame frame = new JFrame();


frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLayout(new GridLayout(3,3,0,0));

frame.add(new JButton("1"));
frame.add(new JButton("2"));
frame.add(new JButton("3"));
frame.add(new JButton("4"));
frame.add(new JButton("5"));
frame.add(new JButton("6"));
frame.add(new JButton("7"));
frame.add(new JButton("8"));
frame.add(new JButton("9"));

frame.setVisible(true);

}
}

You might also like