FileDocCategorySizeDatePackage
TestTree.javaAPI DocExample1431Mon Nov 09 12:45:50 GMT 1998None

TestTree

public class TestTree extends JFrame

Fields Summary
JTree
tree
DefaultTreeModel
treeModel
Constructors Summary
public TestTree()

    super("Tree Test Example");
    setSize(400, 300);
    addWindowListener(new BasicWindowMonitor());
  
Methods Summary
public voidinit()

    // Build up a bunch of TreeNodes. We use DefaultMutableTreeNode because the
    // DefaultTreeModel can use that to build a complete tree.
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode subroot = new DefaultMutableTreeNode("SubRoot");
    DefaultMutableTreeNode leaf1 = new DefaultMutableTreeNode("Leaf 1");
    DefaultMutableTreeNode leaf2 = new DefaultMutableTreeNode("Leaf 2");
    
    // Build our tree model starting at the root node, and then make a JTree out
    // of that.
    treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);

    // Build the tree up from the nodes we created
    treeModel.insertNodeInto(subroot, root, 0);
    treeModel.insertNodeInto(leaf1, subroot, 0);
    treeModel.insertNodeInto(leaf2, root, 1);

    // And display it
    getContentPane().add(tree, BorderLayout.CENTER);
  
public static voidmain(java.lang.String[] args)

    TestTree tt = new TestTree();
    tt.init();
    tt.setVisible(true);