List of usage examples for javax.swing JTree getRowCount
@BeanProperty(bound = false) public int getRowCount()
From source file:Main.java
public static void main(String[] argv) throws Exception { JTree tree = new JTree(); int startRow = tree.getRowCount() - 1; String prefix = "b"; TreePath path = tree.getNextMatch(prefix, startRow, Position.Bias.Backward); System.out.println(path);/* w ww . ja va 2s . com*/ }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i);//from ww w .j av a2 s . c o m } f.add(new JScrollPane(tree)); f.pack(); f.setSize(200, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame("Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.putClientProperty("JTree.lineStyle", "Angled"); // tree.putClientProperty("JTree.lineStyle", "Horizontal"); // tree.putClientProperty("JTree.lineStyle", "None"); for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i);/* w w w. j a va2s . c o m*/ } f.add(tree); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void collapseAllNodes(JTree tree) { int row = tree.getRowCount() - 1; while (row > 0) { tree.collapseRow(row);//from w ww .j a va2s . c om --row; } }
From source file:Main.java
public static void expandAllNodes(JTree tree) { int row = 0;//from w w w . j av a 2s.c o m while (row < tree.getRowCount()) { tree.expandRow(row); ++row; } }
From source file:Main.java
public static void expandJTree(JTree toexpand) { // replace this with a sensible implementation if it fails for (int row = 0; row < toexpand.getRowCount(); ++row) { toexpand.expandRow(row);/*from w ww. j a v a2 s. c o m*/ } }
From source file:Main.java
private static int getStopRow(JTree tree, int startRow) { int startDepth = tree.getPathForRow(startRow).getPathCount(); int last = tree.getRowCount(); int stopRow = last; for (int i = startRow + 1; i < last; ++i) { int depth = tree.getPathForRow(i).getPathCount(); if (depth <= startDepth) { stopRow = i;/*from w ww . j a v a2 s . c o m*/ break; } } return stopRow; }
From source file:Main.java
/** * Stolen from http://stackoverflow.com/a/19935987/5620200 * @param tree// w w w .j a v a 2 s . c o m * @param startingIndex * @param rowCount */ public static void expand(JTree tree, int startingIndex, int rowCount) { for (int i = startingIndex; i < rowCount; ++i) { tree.expandRow(i); } if (tree.getRowCount() != rowCount) { expand(tree, rowCount, tree.getRowCount()); } }
From source file:ec.nbdemetra.ui.demo.ComponentsDemo.java
private static void expandAll(JTree tree) { int row = 0;//from w w w . j a va 2 s . com while (row < tree.getRowCount()) { tree.expandRow(row); row++; } }
From source file:Main.java
/** * Saves the current expansion state of a JTree and returns it in an Enumeration for storing purposes. Example: A * JTree that has all its branches collapsed will return a TreeExpansionState of ",0". * /*w ww . ja v a 2s. co m*/ * @param tree * Save the current expansion state of this tree * @return The current expansion state of the given tree as Enumeration<TreePath> */ public static String getTreeExpansionState(JTree tree, int row) { TreePath rowPath = tree.getPathForRow(row); StringBuilder sb = new StringBuilder(); int rowCount = tree.getRowCount(); for (int i = row; i < rowCount; i++) { TreePath path = tree.getPathForRow(i); if (i == row || isDescendant(path, rowPath)) { if (tree.isExpanded(path)) sb.append("," + String.valueOf(i - row)); } else { break; } } return sb.toString(); }