strom
DefaultMutableTreeNode root = new DefaultMutableTreeNode ("abc"); DefaultMutableTreeNode node = new DefaultMutableTreeNode ("klm"); root.add (node); treeModel = new DefaultTreeModel (root); jTree1.setModel(treeModel);
if (root != null && treeModel != null) { DefaultMutableTreeNode node = new DefaultMutableTreeNode ("rst"); treeModel.insertNodeInto (node, root, 0); }
private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt) { TreePath p = evt.getPath (); Object last = p.getLastPathComponent(); if (last instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) last; Object obj = node.getUserObject(); if (obj instanceof Container && node.getChildCount() == 0) { Container c = (Container) obj; for (Component t : c.getComponents()) { DefaultMutableTreeNode n = new DefaultMutableTreeNode (t); treeModel.insertNodeInto (n, node, node.getChildCount()); } } } }
strom.txt · Last modified: 2011/11/24 15:58 by 127.0.0.1