-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path55_GridLayout
More file actions
31 lines (26 loc) · 1.01 KB
/
55_GridLayout
File metadata and controls
31 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Layout Manager = Defines the natural layout for components within a container
//3 common managers
//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
import javax.swing.*;
import java.awt.*;
public class Main{
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setLayout(new GridLayout(3,3,10,10));//row,column,hgap,vgap
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.add(new JButton("10"));
frame.setVisible(true); //after button->so can directly show
}
}