List of utility methods to do JTree
String | getExpansionState(JTree tree, int row) get Expansion State TreePath rowPath = tree.getPathForRow(row); StringBuffer buf = new StringBuffer(); 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)) buf.append("," + String.valueOf(i - row)); ... |
JTree | getProjectTree() get Project Tree return mProjectTree;
|
ArrayList | getSelectionFromTree(JTree tree) get Selection From Tree ArrayList<String> list = new ArrayList<String>(); TreePath[] nodes = tree.getSelectionPaths(); for (int i = 0; i < nodes.length; i++) { TreePath temp = nodes[i]; Object tempObj = temp.getLastPathComponent(); DefaultMutableTreeNode treNode = (DefaultMutableTreeNode) tempObj; String device = String.valueOf(treNode.getUserObject()); list.add(device); ... |
int | getStopRow(JTree tree, int startRow) get Stop Row 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; break; ... |
ImageIcon | getTreeImage(String imageName) get Tree Image String imageFileName = PATHFORIMAGEFILES + imageName; ImageIcon treeImageIcon = null; try { Vector v = new Vector(); InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(imageFileName); if (is == null) is = ClassLoader.getSystemResourceAsStream(PATHFORIMAGEFILES + "unknown.gif"); is = new BufferedInputStream(is); ... |
T | getTreeObject(JTree tree, Class Searches the given tree's selection path for a Node of the given type. TreePath[] paths = tree.getSelectionPaths(); if (paths == null || paths.length == 0) { return null; for (int i = 0; i < paths.length; i++) { TreePath path = paths[i]; for (Object o : path.getPath()) { if (o.getClass().equals(type)) ... |
Color | getTreeSelectionBorderColor() get Tree Selection Border Color return UIManager.getColor("Tree.selectionBorderColor"); |
boolean | isPointOnTree(JTree tree, Point location) Determines whether a point is on a row in a tree, or is outside the tree rows. return (tree.getRowForLocation(location.x, location.y) != -1);
|
void | maxDepth(JTree tree, int depth) max Depth collapse(tree, depth); expand(tree, depth); |
void | paint(JTree tree) Richiama il metodo paintImmediately() del JTree Rectangle r = tree.getBounds(); int rowVisible = tree.getVisibleRowCount(); Rectangle rv = new Rectangle(r.width, r.height + rowVisible); tree.paintImmediately(rv); |