-
Notifications
You must be signed in to change notification settings - Fork 0
/
BorderLayoutExample.java
42 lines (35 loc) · 1.17 KB
/
BorderLayoutExample.java
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
37
38
39
40
41
42
import java.awt.*;
import javax.swing.*;
public class BorderLayoutExample
{
BorderLayoutExample()
{
JFrame frame = new JFrame("Border Layout");
frame.setSize(400, 400);
frame.setResizable(false);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout(2,2));
JButton b1 = new JButton("Button 1");
JButton b2 = new JButton("Button 2");
JButton b3 = new JButton("Button 3");
JButton b4 = new JButton("Button 4");
JButton b5 = new JButton("Button 5");
b1.setBorder(BorderFactory.createLineBorder(Color.red));
b2.setBorder(BorderFactory.createLineBorder(Color.red));
b3.setBorder(BorderFactory.createLineBorder(Color.red));
b4.setBorder(BorderFactory.createLineBorder(Color.red));
b5.setBorder(BorderFactory.createLineBorder(Color.red));
panel.add(b1, BorderLayout.NORTH);
panel.add(b5, BorderLayout.SOUTH);
panel.add(b2, BorderLayout.WEST);
panel.add(b4, BorderLayout.EAST);
panel.add(b3, BorderLayout.CENTER);
frame.add(panel);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new BorderLayoutExample();
}
}