List of usage examples for javax.swing JTree JTree
@ConstructorProperties({ "model" }) public JTree(TreeModel newModel)
JTree
which displays the root node -- the tree is created using the specified data model. From source file:Main.java
public static void main(String[] args) { JTree tree = new JTree(new TestModel()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tree)); frame.pack();/*from w ww . j ava 2 s. c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(10, 11, 212, 500); frame.getContentPane().add(scrollPane); JTree tree = new JTree(addNodes(new File("."))); tree.setRootVisible(false);//w w w.jav a 2s . co m tree.setShowsRootHandles(true); tree.setBorder(new LineBorder(new Color(0, 0, 0))); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); scrollPane.setViewportView(tree); tree.setCellRenderer(new FileTreeCellRenderer()); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); DefaultTreeModel model = new DefaultTreeModel(root); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(new JTree(model))); f.getContentPane().add(new JButton(new AbstractAction("Add thousand children") { @Override//w w w . ja v a 2s. co m public void actionPerformed(ActionEvent e) { int offset = root.getChildCount() + 1; for (int i = 0; i < 1000; i++) { DefaultMutableTreeNode child = new DefaultMutableTreeNode("Person " + (i + offset)); // model.insertNodeInto(child, root, root.getChildCount()); root.add(child); } model.nodeStructureChanged(root); } }), BorderLayout.PAGE_END); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(Main.class.getSimpleName()); DefaultTreeModel model = getTreeModel(); JTree tree1 = new JTree(model); JTree tree2 = new JTree(model); frame.add(new JScrollPane(tree1), BorderLayout.WEST); frame.add(new JScrollPane(tree2), BorderLayout.EAST); frame.pack();/*ww w . jav a2s .c o m*/ frame.setSize(frame.getWidth() + 50, frame.getHeight() + 140); frame.setVisible(true); Timer t = new Timer(2000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.add(new DefaultMutableTreeNode("A new node")); model.nodesWereInserted(root, new int[] { root.getChildCount() - 1 }); tree1.expandRow(0); tree2.expandRow(0); frame.revalidate(); } }); t.start(); }
From source file:CreatingTreeModel.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FileSystemModel fileSystemDataModel = new FileSystemModel(); JTree tree = new JTree(fileSystemDataModel); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane);// w w w .j a v a 2 s .com frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { DefaultMutableTreeNode root = new DefaultMutableTreeNode("Days"); for (DaysOfTheWeek dotw : DaysOfTheWeek.values()) { root.add(new DefaultMutableTreeNode(dotw)); }//from www. j a v a2s .co m final DefaultTreeModel model = new DefaultTreeModel(root); JTree tree = new JTree(model); tree.setRootVisible(true); tree.setShowsRootHandles(true); ToolTipManager.sharedInstance().registerComponent(tree); tree.setCellRenderer(new MyTreeCellRenderer()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(tree)); f.pack(); f.setVisible(true); }
From source file:TreeTips.java
public static void main(String args[]) { JFrame frame = new JFrame("Tree Tips"); Properties props = System.getProperties(); JTree tree = new JTree(props); ToolTipManager.sharedInstance().registerComponent(tree); TreeCellRenderer renderer = new ToolTipTreeCellRenderer(props); tree.setCellRenderer(renderer);/*ww w .ja v a 2 s. c o m*/ JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeArraySample.java
public static void main(String args[]) { JFrame frame = new JFrame("JTreeSample"); Vector oneVector = new NamedVector("One", args); Vector twoVector = new NamedVector("Two", new String[] { "Mercury", "Venus", "Mars" }); Vector threeVector = new NamedVector("Three"); threeVector.add(System.getProperties()); threeVector.add(twoVector);/* w w w . j av a2s .c o m*/ Object rootNodes[] = { oneVector, twoVector, threeVector }; Vector rootVector = new NamedVector("Root", rootNodes); JTree tree = new JTree(rootVector); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); // frame.getContentPane().add(tree, BorderLayout.CENTER); frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); DefaultMutableTreeNode mercury = new DefaultMutableTreeNode("Mercury"); root.insert(mercury, 0);/*from ww w. jav a2 s. co m*/ DefaultMutableTreeNode venus = new DefaultMutableTreeNode("Venus"); root.insert(venus, 1); DefaultMutableTreeNode mars = new DefaultMutableTreeNode("Mars"); root.insert(mars, 2); JTree tree = new JTree(root); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:DefaultMutableTreeNodeAddingDemo.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); DefaultMutableTreeNode mercury = new DefaultMutableTreeNode("Mercury"); root.add(mercury);//from ww w .j a v a 2 s .c o m DefaultMutableTreeNode venus = new DefaultMutableTreeNode("Venus"); root.add(venus); DefaultMutableTreeNode mars = new DefaultMutableTreeNode("Mars"); root.add(mars); JTree tree = new JTree(root); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }