Methods Summary |
---|
public javax.swing.tree.DefaultMutableTreeNode | addObject(java.lang.Object child)Add child to the currently selected node.
DefaultMutableTreeNode parentNode = null;
TreePath parentPath = tree.getSelectionPath();
if (parentPath == null) {
parentNode = rootNode;
} else {
parentNode = (DefaultMutableTreeNode)
(parentPath.getLastPathComponent());
}
return addObject(parentNode, child, true);
|
public javax.swing.tree.DefaultMutableTreeNode | addObject(javax.swing.tree.DefaultMutableTreeNode parent, java.lang.Object child)
return addObject(parent, child, false);
|
public javax.swing.tree.DefaultMutableTreeNode | addObject(javax.swing.tree.DefaultMutableTreeNode parent, java.lang.Object child, boolean shouldBeVisible)
DefaultMutableTreeNode childNode =
new DefaultMutableTreeNode(child);
if (parent == null) {
parent = rootNode;
}
treeModel.insertNodeInto(childNode, parent,
parent.getChildCount());
// Make sure the user can see the lovely new node.
if (shouldBeVisible) {
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
}
return childNode;
|
public void | clear()Remove all nodes except the root node.
rootNode.removeAllChildren();
treeModel.reload();
|
public void | removeCurrentNode()Remove the currently selected node.
TreePath currentSelection = tree.getSelectionPath();
if (currentSelection != null) {
DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)
(currentSelection.getLastPathComponent());
MutableTreeNode parent = (MutableTreeNode)(currentNode.getParent());
if (parent != null) {
treeModel.removeNodeFromParent(currentNode);
return;
}
}
// Either there was no selection, or the root was selected.
toolkit.beep();
|