FileDocCategorySizeDatePackage
VSX2.javaAPI DocExample4746Thu Oct 24 20:14:26 BST 2002None

VSX2

public class VSX2 extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    if (args.length != 1) {
      System.err.println("Usage is: java VSX2 testfile.xml");
      System.exit(1);
    }
    JFrame frame = new JFrame("Tree Renderer Test");
    VSX2 parser = new VSX2();
    JTree tree = new JTree(parser.parse(args[0]));

    // Steal the default icons from the default renderer...
    DefaultTreeCellRenderer rend1 = new DefaultTreeCellRenderer();
    IconAndTipRenderer rend2 = new IconAndTipRenderer(
      rend1.getOpenIcon(),
      rend1.getClosedIcon(),
      rend1.getLeafIcon());
    tree.setCellRenderer(rend2);
    ToolTipManager.sharedInstance().registerComponent(tree);

    frame.getContentPane().add(new JScrollPane(tree));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300,400);
    frame.setVisible(true);
  
public javax.swing.tree.TreeModelparse(java.lang.String filename)

    SAXParserFactory factory = SAXParserFactory.newInstance();
    XMLIconTreeHandler handler = new XMLIconTreeHandler();
    try {
      // Parse the input
      SAXParser saxParser = factory.newSAXParser();
      saxParser.parse( new File(filename), handler);
    }
    catch (Exception e) {
      System.err.println("File Read Error: " + e);
      e.printStackTrace();
      return new DefaultTreeModel(new DefaultMutableTreeNode("error"));
    }
    return new DefaultTreeModel(handler.getRoot());