-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path54_Flow Layout
More file actions
36 lines (29 loc) · 1.26 KB
/
54_Flow Layout
File metadata and controls
36 lines (29 loc) · 1.26 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
32
33
34
35
36
//Layout Manager = Defines the natural layout for components within a container
//3 common managers
//FlowLayout = places components in a row, sized at their preferred size.
// If the horizontal space in the container is too small.
// the FlowLayout class uses the next available row
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 FlowLayout(FlowLayout.CENTER,10,10));//LEADING(left), CENTER(default), TRAILING(Right); hgap, vgap
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(100,250));
panel.setBackground(Color.lightGray);
panel.setLayout(new FlowLayout()); //default alr have
panel.add(new JButton("1"));
panel.add(new JButton("2"));
panel.add(new JButton("3"));
panel.add(new JButton("4"));
panel.add(new JButton("5"));
panel.add(new JButton("6"));
panel.add(new JButton("7"));
panel.add(new JButton("8"));
panel.add(new JButton("9"));
frame.setVisible(true); //after button->so can directly show
}
}