Java Code Examples for javax.swing.JTree#setSelectionPaths()
The following examples show how to use
javax.swing.JTree#setSelectionPaths() .
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: JTreeJavaElement.java From marathonv5 with Apache License 2.0 | 6 votes |
private boolean setCellSelection(Properties[] properties) { JTree tree = (JTree) component; if (properties.length == 0) { tree.setSelectionRows(new int[0]); return true; } List<TreePath> paths = new ArrayList<TreePath>(); for (Properties propertie : properties) { TreePath path = getPath(tree, propertie.getProperty("Path")); if (path != null) { paths.add(path); } } if (paths.size() != properties.length) { return false; } tree.setSelectionPaths(paths.toArray(new TreePath[paths.size()])); return true; }
Example 2
Source File: RepositoryTreeUtil.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Expands all repositories and nodes, which have been saved before. Restores selected paths, * which have been saved proviously. * * @param tree * The related tree, containing the path(s) */ public void restoreExpansionState(JTree tree) { List<TreePath> selectedPathList = new ArrayList<>(); for (int i = 0; i < tree.getRowCount(); i++) { TreePath path = tree.getPathForRow(i); // sanity check for concurrent refreshes if (path != null) { Object entryObject = path.getLastPathComponent(); if (entryObject instanceof Entry) { Entry entry = (Entry) entryObject; RepositoryLocation absoluteLocation = entry.getLocation(); if (expandedNodes.contains(absoluteLocation)) { tree.expandPath(path); } if (selectedNodes.contains(absoluteLocation)) { selectedPathList.add(path); } } } } if (!selectedPathList.isEmpty()) { tree.setSelectionPaths(selectedPathList.toArray(new TreePath[0])); } }
Example 3
Source File: ProfilerTreeTable.java From netbeans with Apache License 2.0 | 5 votes |
static void restoreSelectedNodes(JTree tree, UIState uiState) { try { TreePath[] sel = uiState.getSelectedPaths(); if (sel != null) for (int i = 0; i < sel.length; i++) sel[i] = getSimilarPath(sel[i], tree.getModel()); tree.setSelectionPaths(sel); } catch (Exception e) { System.err.println(">>> Exception in ProfilerTreeTable.restoreSelectedNodes: " + e.getMessage()); e.printStackTrace(); } }
Example 4
Source File: ProfilerTreeTable.java From visualvm with GNU General Public License v2.0 | 5 votes |
static void restoreSelectedNodes(JTree tree, UIState uiState) { try { TreePath[] sel = uiState.getSelectedPaths(); if (sel != null) for (int i = 0; i < sel.length; i++) sel[i] = getSimilarPath(sel[i], tree.getModel()); tree.setSelectionPaths(sel); } catch (Exception e) { System.err.println(">>> Exception in ProfilerTreeTable.restoreSelectedNodes: " + e.getMessage()); e.printStackTrace(); } }
Example 5
Source File: EntityTreePanel.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
/** * list all entities in the world. Double click an item to get its panel. * See https://docs.oracle.com/javase/7/docs/api/javax/swing/JTree.html */ public void updateEntityTree() { // list all objects in scene DefaultMutableTreeNode newTop = createTreeNodes(ro); JTree newTree = new JTree(newTop); newTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); newTree.setShowsRootHandles(true); newTree.addTreeSelectionListener(this); //tree.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); if(oldTree!=null) { // preserve the original expansions ArrayList<TreePath> expanded = new ArrayList<TreePath>(); for(int i=0;i<oldTree.getRowCount();++i) { if(oldTree.isExpanded(i)) { expanded.add(oldTree.getPathForRow(i)); } } // restore the expanded paths for(TreePath p : expanded) { newTree.expandPath(p); } // restore the selected paths TreePath[] paths = oldTree.getSelectionPaths(); newTree.setSelectionPaths(paths); } if(!newTree.equals(oldTree)) { scroll.setViewportView(newTree); oldTree=newTree; oldTop =newTop; } }
Example 6
Source File: RepositoryTreeUtil.java From rapidminer-studio with GNU Affero General Public License v3.0 | 3 votes |
/** * Sets selected paths to the previous path(s) saved by {@link #saveSelectionPath(TreePath)} or * ##{@link #saveSelectionPaths(TreePath[])}. Scrolls to the first selected path. * * @param tree * The related tree, containing the path(s) */ public void restoreSelectionPaths(JTree tree) { if (selectedPaths != null) { tree.setSelectionPaths(selectedPaths); tree.scrollPathToVisible(tree.getSelectionPath()); } }