List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:Main.java
public static void main(String[] args) { JTree tree = new JTree(); Enumeration en = ((DefaultMutableTreeNode) tree.getModel().getRoot()).preorderEnumeration(); while (en.hasMoreElements()) { TreePath path = new TreePath(((DefaultMutableTreeNode) en.nextElement()).getPath()); String text = path.toString(); System.out.println(text); }/*from w ww. j a v a 2s. c o m*/ }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Swing Package Hierarchy"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector rootVector = new TreeVector("A", new String[] { "a" }); JTree tree = new JTree(rootVector); tree.setRootVisible(true);/* w ww. j a va 2 s.c om*/ TreeModel model = tree.getModel(); model.valueForPathChanged(new TreePath(model.getRoot()), "javax.swing"); ((DefaultTreeModel) model).reload(); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); final JTree tree = new JTree(); panel.add(new JScrollPane(tree)); JButton btn = new JButton("Press Me"); btn.addActionListener(et -> {/*from w ww. java2 s.c o m*/ for (Enumeration e = ((TreeNode) tree.getModel().getRoot()).children(); e.hasMoreElements();) { TreeNode tn = (TreeNode) e.nextElement(); tree.expandPath(new TreePath(((DefaultTreeModel) tree.getModel()).getPathToRoot(tn))); } }); panel.add(btn, BorderLayout.SOUTH); JFrame frame = new JFrame(""); frame.getContentPane().add(panel); frame.setSize(300, 300); frame.setLocation(100, 100); frame.pack(); frame.show(); }
From source file:Main.java
public static void expandTree(JTree tree) { expandTree(tree, new TreePath(tree.getModel().getRoot())); }
From source file:Main.java
static public void expandAll(JTree tree, boolean expand) { Object root = tree.getModel().getRoot(); // Traverse tree from root expandAll(tree, new TreePath(root), expand); }
From source file:TreeUtil.java
public static void expandAll(JTree tree, boolean expand) { TreeNode root = (TreeNode) tree.getModel().getRoot(); // Traverse tree from root expandAll(tree, new TreePath(root), expand); }
From source file:Main.java
public static void visitAllExpandedNodes(JTree tree) { TreeNode root = (TreeNode) tree.getModel().getRoot(); visitAllExpandedNodes(tree, new TreePath(root)); }
From source file:Main.java
public static void expand(JTree tree, int level) { DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) tree.getModel().getRoot(); while (currentNode != null) { if (currentNode.getLevel() <= level) { tree.expandPath(new TreePath(currentNode.getPath())); }/* w ww .j a va2s. co m*/ currentNode = currentNode.getNextNode(); } }
From source file:Main.java
public static void expandTreeNode(JTree tree, DefaultMutableTreeNode node, int depth) { if (depth <= 0) { return;// w ww.java2 s . c o m } tree.expandPath(new TreePath(node.getPath())); for (int i = 0; i < node.getChildCount(); i++) { expandTreeNode(tree, (DefaultMutableTreeNode) node.getChildAt(i), depth - 1); } }
From source file:Main.java
public static TreePath findByName(JTree tree, String[] names) { TreeNode root = (TreeNode) tree.getModel().getRoot(); return find(tree, new TreePath(root), names, 0); }