blob: 1448c9d2aebda1c2bf9448c691f58120d34ac786 (
plain)
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
|
/* Listing3811.java */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class Listing3811
extends JFrame
{
public Listing3811()
{
super("JTree 1");
addWindowListener(new WindowClosingAdapter(true));
//Einfaches TreeModel bauen
DefaultMutableTreeNode root, child, subchild;
root = new DefaultMutableTreeNode("Root");
for (int i = 1; i <= 5; ++i) {
String name = "Child-" + i;
child = new DefaultMutableTreeNode(name);
root.add(child);
for (int j = 1; j <= 3; ++j) {
subchild = new DefaultMutableTreeNode(name + "-" + j);
child.add(subchild);
}
}
//JTree erzeugen
JTree tree = new JTree(root);
tree.setRootVisible(true);
//JTree einf�gen
Container cp = getContentPane();
cp.add(new JScrollPane(tree), BorderLayout.CENTER);
}
public static void main(String[] args)
{
Listing3811 frame = new Listing3811();
frame.setLocation(100, 100);
frame.setSize(250, 200);
frame.setVisible(true);
}
}
|