Java Code Examples for javax.swing.tree.DefaultTreeModel#getPathToRoot()
The following examples show how to use
javax.swing.tree.DefaultTreeModel#getPathToRoot() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JByteMod.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
private boolean selectEntry(MethodNode mn, DefaultTreeModel tm, SortedTreeNode node) { for (int i = 0; i < tm.getChildCount(node); i++) { SortedTreeNode child = (SortedTreeNode) tm.getChild(node, i); if (child.getMn() != null && child.getMn().equals(mn)) { TreePath tp = new TreePath(tm.getPathToRoot(child)); jarTree.setSelectionPath(tp); jarTree.scrollPathToVisible(tp); return true; } if (!child.isLeaf()) { if (selectEntry(mn, tm, child)) { return true; } } } return false; }
Example 2
Source File: HelpViewerWindow.java From bigtable-sql with Apache License 2.0 | 6 votes |
private void selectTreeNodeForURL(URL url) { // Strip local part of URL. String key = url.toString(); final int idx = key.lastIndexOf('#'); if (idx > -1) { key = key.substring(0, idx); } DefaultMutableTreeNode node = _nodes.get(key); if (node != null) // && node != _tree.getLastSelectedPathComponent()) { DefaultTreeModel model = (DefaultTreeModel) _tree.getModel(); TreePath path = new TreePath(model.getPathToRoot(node)); if (path != null) { _tree.expandPath(path); _tree.scrollPathToVisible(path); _tree.setSelectionPath(path); } } }
Example 3
Source File: BaseTemplateAction.java From CodeGen with MIT License | 5 votes |
/** * 直接通过model来添加新节点,则无需通过调用JTree的updateUI方法 * model.insertNodeInto(newNode, selectedNode, selectedNode.getChildCount()); * 直接通过节点添加新节点,则需要调用tree的updateUI方法 */ private void addNode(DefaultMutableTreeNode pNode, MutableTreeNode newNode){ pNode.add(newNode); //--------下面代码实现显示新节点(自动展开父节点)------- DefaultTreeModel model = (DefaultTreeModel) this.templateTree.getModel(); TreeNode[] nodes = model.getPathToRoot(newNode); TreePath path = new TreePath(nodes); this.templateTree.scrollPathToVisible(path); this.templateTree.updateUI(); }
Example 4
Source File: AbstractTab.java From DiskBrowser with GNU General Public License v3.0 | 5 votes |
protected TreePath getPathToNode (DefaultMutableTreeNode selectNode) // ---------------------------------------------------------------------------------// { DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel (); TreeNode[] nodes = treeModel.getPathToRoot (selectNode); if (nodes == null) return null; return new TreePath (nodes); }