-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxLayout.java
More file actions
31 lines (26 loc) · 890 Bytes
/
BoxLayout.java
File metadata and controls
31 lines (26 loc) · 890 Bytes
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
import javax.swing.*;
class MyFrame4 extends JFrame {
MyFrame4() {
setSize(480, 320);
setTitle("My Frame Title");
// first we create three buttons
JButton btn1 = new JButton("Button 1");
JButton btn2 = new JButton("Button 2");
JButton btn3 = new JButton("Button 3");
// then we create a panel to hold the buttons
JPanel pnl = new JPanel();
BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
pnl.setLayout(layout);
// we add the three buttons to the panel
pnl.add(btn1);
pnl.add(btn2);
pnl.add(btn3);
// finally we set the panel as the content pane of the frame
setContentPane(pnl);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new MyFrame4();
}
}