List of utility methods to do JTree
DefaultMutableTreeNode | pickFirstIfNone(JTree tree) If an explicit pick has not been done then null will be returned. DefaultMutableTreeNode result = null; if (tree.isSelectionEmpty()) { tree.setSelectionRow(0); if (tree.getSelectionCount() != 1) { } else { TreePath treePath = tree.getSelectionPath(); DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); ... |
void | printComponentTree(final JComponent fc) print Component Tree printComponentTree(fc, "");
|
void | RemoveAll(JTree tree) Remove All RemoveChildren((DefaultMutableTreeNode) tree.getModel().getRoot()); tree.updateUI(); |
void | repaintSelection(JTree tree) Repaints the selection. int[] selectedRows = tree.getSelectionRows(); if (selectedRows != null && selectedRows.length > 0) { Rectangle firstSelectedCell = tree.getRowBounds(selectedRows[0]); Rectangle lastSelectedCell = tree.getRowBounds(selectedRows[selectedRows.length - 1]); Rectangle repaintRectangle = firstSelectedCell.union(lastSelectedCell); repaintRectangle.x = 0; repaintRectangle.width = tree.getWidth(); tree.repaint(repaintRectangle); ... |
void | restoreExpanstionState(JTree tree, int row, String expansionState) restore Expanstion State StringTokenizer stok = new StringTokenizer(expansionState, ","); while (stok.hasMoreTokens()) { int token = row + Integer.parseInt(stok.nextToken()); tree.expandRow(token); |
void | revalidateTree(java.awt.Component c) revalidate Tree if (c instanceof javax.swing.JComponent) { javax.swing.JComponent jc = (javax.swing.JComponent) c; jc.revalidate(); if (c instanceof java.awt.Container) { java.awt.Container container = (java.awt.Container) c; for (java.awt.Component component : container.getComponents()) { revalidateTree(component); ... |
Enumeration | saveExpansionState(JTree tree) Save the expansion state of a tree. return tree.getExpandedDescendants(new TreePath(tree.getModel().getRoot())); |
ArrayList | saveExpansionStateStrings(JTree tree) save Expansion State Strings ArrayList<String> result = new ArrayList<String>(); Enumeration<TreePath> expansionState = tree.getExpandedDescendants(new TreePath(tree.getModel().getRoot())); if (expansionState != null) { while (expansionState.hasMoreElements()) { TreePath treePath = (TreePath) expansionState.nextElement(); result.add(treePath.toString()); return result; |
TreePath[] | saveTreeSelection(JTree tree) save Tree Selection return tree == null ? null : tree.getSelectionPaths();
|
void | scrollToSelection(JTree tree) scroll To Selection if (!(tree.getParent() instanceof JViewport)) return; setViewPortPosition((JViewport) tree.getParent(), tree.getPathBounds(tree.getSelectionPath())); |