List of usage examples for javax.swing JTree JTree
public JTree()
JTree
with a sample model. 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); }/* w w w . j av a 2s .com*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTree tree = new JTree(); JFrame f = new JFrame(); f.add(new JScrollPane(tree)); f.setSize(300, 300);/*from w w w .j a v a2s.c o m*/ f.setVisible(true); // Get paths of all selected nodes TreePath[] paths = tree.getSelectionPaths(); }
From source file:TreeSingleSelection.java
public static void main(String[] argv) { JTree tree = new JTree(); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); JFrame frame = new JFrame("Tree single selection"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(tree)); frame.setSize(380, 320);//w w w.j a v a2 s.c o m frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTree tree = new JTree(); visitAllExpandedNodes(tree);//from w w w. j a v a 2 s . c om }
From source file:TreeSelectionOption.java
public static void main(String[] argv) { JTree tree = new JTree(); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(tree)); frame.setSize(380, 320);/*from w w w.j ava2s . c o m*/ frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:TreeDISCONTIGUOUSSelection.java
public static void main(String[] argv) { JTree tree = new JTree(); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JFrame frame = new JFrame("tree DISCONTIGUOUS selection"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(tree)); frame.setSize(380, 320);/*w w w. j a v a 2s .c o m*/ frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTree tree = new JTree(); TreePath path = findByName(tree, new String[] { "JTree", "A", "a" }); }
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);/*from www. ja v a2s . c o m*/ } f.add(tree); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
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);//w w w . ja v a 2 s . com } f.add(new JScrollPane(tree)); f.pack(); f.setSize(200, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTree tree = new JTree(); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath[] paths = evt.getPaths(); for (int i = 0; i < paths.length; i++) { if (evt.isAddedPath(i)) { System.out.println("This node has been selected"); } else { System.out.println("This node has been deselected"); }// w w w . ja v a2 s .c o m } } }); }