![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e1025. Adding a Node to a JTree Component// Create tree JTree tree = new JTree(); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); // Find node to which new node is to be added int startRow = 0; String prefix = "J"; TreePath path = tree.getNextMatch(prefix, startRow, Position.Bias.Forward); MutableTreeNode node = (MutableTreeNode)path.getLastPathComponent(); // Create new node MutableTreeNode newNode = new DefaultMutableTreeNode("green"); // Insert new node as last child of node model.insertNodeInto(newNode, node, node.getChildCount());
e1024. Finding a Node in a JTree Component e1026. Removing a Node to a JTree Component e1027. Converting a Node in a JTree Component to a TreePath e1028. Converting All Nodes in a JTree Component to a TreePath Array
© 2002 Addison-Wesley. |