Java Reference
In-Depth Information
putClientProperty("JTree.lineStyle","Angled") is used to display the an-
gled lines corresponding to tree's edges. Alternatives to 'Angled' are 'Horizontal',
where horizontal lines between the nodes indicate the structure, and 'None'
where only indentation is used.
16.4.4
Sample applications
In the first sample application we define a tree manually. The structure is like the
one in Figure 16.6. The labels are to reflect a simple taxonomy of plants. Class
BiologyTree is derived from JTree .Itcontains an instance biologyTreeModel
of class DefaultTreeModel . The tree model is constructed by defining the root
node and adding other nodes as children of existing ones.
The classes TreeFrame and TreeDemoDriver are also listed.
File: its/Trees/BiologyTree.java
package its.Trees;
1.
2.
3.
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
4.
import javax.swing.tree.DefaultTreeModel;
5.
6.
7.
public class BiologyTree extends JTree {
8.
9.
private DefaultTreeModel biologyTreeModel;
10.
11.
public BiologyTree(){
12.
makeModel();
13.
this .setModel(biologyTreeModel);
14.
this .putClientProperty("JTree.lineStyle","Angled");
15.
}
16.
17.
private void makeModel(){
18.
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Trees");
19.
DefaultMutableTreeNode leaved
= new DefaultMutableTreeNode("Leaved Trees");
20.
DefaultMutableTreeNode conifer
= new DefaultMutableTreeNode("Conifers");
DefaultMutableTreeNode beech
= new DefaultMutableTreeNode("Beech");
21.
DefaultMutableTreeNode oak
= new DefaultMutableTreeNode("Oak");
22.
DefaultMutableTreeNode birch
= new DefaultMutableTreeNode("Birch");
23.
DefaultMutableTreeNode pine
= new DefaultMutableTreeNode("Pine");
24.
DefaultMutableTreeNode fir
= new DefaultMutableTreeNode("Fir");
25.
DefaultMutableTreeNode beechR
= new DefaultMutableTreeNode("Red Leaved");
26.
Search WWH ::




Custom Search