-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathNestedPanelsExample.java
More file actions
32 lines (26 loc) · 1.1 KB
/
NestedPanelsExample.java
File metadata and controls
32 lines (26 loc) · 1.1 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
import javax.swing.*;
public class NestedPanelsExample {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JPanel firstNamePanel = new JPanel();
firstNamePanel.add(new JLabel("First Name:"));
firstNamePanel.add(new JTextField(10));
JPanel lastNamePanel = new JPanel();
lastNamePanel.add(new JLabel("Last Name:"));
lastNamePanel.add(new JTextField(10));
JPanel buttonPanel = new JPanel();
buttonPanel.add(new JButton("Submit"));
buttonPanel.add(new JButton("Cancel"));
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
mainPanel.add(firstNamePanel);
mainPanel.add(lastNamePanel);
mainPanel.add(buttonPanel);
JFrame frame = new JFrame("Nested Panels Example");
frame.setContentPane(mainPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
});
}
}