FileDocCategorySizeDatePackage
TestTree4.javaAPI DocExample2025Thu Oct 24 20:14:26 BST 2002None

TestTree4

public class TestTree4 extends JFrame

Fields Summary
JTree
tree1
JTree
tree2
DefaultTreeModel
treeModel
Constructors Summary
public TestTree4()

    super("Custom Icon Example");
    setSize(350, 450);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    // Build the hierarchy of containers & objects
    String[] schoolyard = {"School", "Playground", "Parking Lot", "Field"};
    String[] mainstreet = {"Grocery", "Shoe Shop", "Five & Dime", 
                           "Post Office"};
    String[] highway = {"Gas Station", "Convenience Store"};
    String[] housing = {"Victorian_blue", "Faux Colonial", 
                        "Victorian_white"};
    String[] housing2 = {"Mission", "Ranch", "Condo"};
    Hashtable homeHash = new Hashtable();
    homeHash.put("Residential 1", housing);
    homeHash.put("Residential 2", housing2);

    Hashtable cityHash = new Hashtable();
    cityHash.put("School grounds", schoolyard);
    cityHash.put("Downtown", mainstreet);
    cityHash.put("Highway", highway);
    cityHash.put("Housing", homeHash);

    Hashtable worldHash = new Hashtable();
    worldHash.put("My First VRML World", cityHash);
    
    // Build our tree out of our big hashtable
    tree1 = new JTree(worldHash);
    tree2 = new JTree(worldHash);

    DefaultTreeCellRenderer renderer = 
      (DefaultTreeCellRenderer)tree2.getCellRenderer();
    renderer.setClosedIcon(new ImageIcon("door.closed.gif"));
    renderer.setOpenIcon(new ImageIcon("door.open.gif"));
    renderer.setLeafIcon(new ImageIcon("world.gif"));

    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
      tree1, tree2);

    getContentPane().add(pane, BorderLayout.CENTER);
  
Methods Summary
public static voidmain(java.lang.String[] args)

    TestTree4 tt = new TestTree4();
    tt.setVisible(true);