-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swing58.java
33 lines (26 loc) · 1.04 KB
/
Swing58.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
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class Swing58 {
public static void main(String[] args) {
JFrame frame = new JFrame("JTree");
frame.setSize(500,500);
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Top");
DefaultMutableTreeNode A = new DefaultMutableTreeNode("A");
DefaultMutableTreeNode B = new DefaultMutableTreeNode("B");
DefaultMutableTreeNode A1 = new DefaultMutableTreeNode("A1");
DefaultMutableTreeNode A2 = new DefaultMutableTreeNode("A2");
DefaultMutableTreeNode B1 = new DefaultMutableTreeNode("B1");
DefaultMutableTreeNode B2 = new DefaultMutableTreeNode("B2");
DefaultMutableTreeNode B3 = new DefaultMutableTreeNode("B3");
A.add(A1);
A.add(A2);
B.add(B1);
B.add(B2);
B.add(B3);
rootNode.add(A);
rootNode.add(B);
JTree tree = new JTree(rootNode);
frame.add(tree);
frame.setVisible(true);
}
}