KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > debug > misc > JTreeASTPanel


1 package persistence.antlr.debug.misc;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/license.html
6  *
7  */

8
9 import java.awt.*;
10 import javax.swing.*;
11 import javax.swing.tree.*;
12 import javax.swing.event.*;
13
14 public class JTreeASTPanel extends JPanel {
15     JTree tree;
16
17     public JTreeASTPanel(TreeModel tm, TreeSelectionListener listener) {
18         // use a layout that will stretch tree to panel size
19
setLayout(new BorderLayout());
20
21         // Create tree
22
tree = new JTree(tm);
23
24         // Change line style
25
tree.putClientProperty("JTree.lineStyle", "Angled");
26
27         // Add TreeSelectionListener
28
if (listener != null)
29             tree.addTreeSelectionListener(listener);
30
31         // Put tree in a scrollable pane's viewport
32
JScrollPane sp = new JScrollPane();
33         sp.getViewport().add(tree);
34
35         add(sp, BorderLayout.CENTER);
36     }
37 }
38
Popular Tags