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[] argv) throws Exception { DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root Label"); root.add(new DefaultMutableTreeNode("Node Label")); JTree tree = new JTree(root); JFrame f = new JFrame(); f.add(new JScrollPane(tree)); f.setSize(300, 300);//from w w w . java2s .c o m f.setVisible(true); }
From source file:TreeNodeRemove.java
public static void main(String[] argv) { Vector<String> v = new Vector<String>(); v.add("a");/*from w w w . j ava 2 s . c om*/ v.add("b"); v.add("c"); JTree tree = new JTree(v); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); int startRow = 0; String prefix = "b"; TreePath path = tree.getNextMatch(prefix, startRow, Position.Bias.Forward); MutableTreeNode node = (MutableTreeNode) path.getLastPathComponent(); model.removeNodeFromParent(node); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(tree)); frame.setSize(380, 320); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" }; JTree tree = new JTree(array); tree.setEditable(true);//from w w w .j a v a2s .c o m tree.setRootVisible(true); JCheckBox checkBox = new JCheckBox(); TreeCellEditor editor = new DefaultCellEditor(checkBox); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeEditJCheckBox.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Properties props = System.getProperties(); JTree tree = new JTree(props); JCheckBox checkBox = new JCheckBox("To be or not to be"); TreeCellEditor editor = new DefaultCellEditor(checkBox); tree.setEditable(true);/*from ww w .j av a 2 s . co m*/ tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeEditJTextField.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Properties props = System.getProperties(); JTree tree = new JTree(props); JTextField textField = new JTextField(); TreeCellEditor editor = new DefaultCellEditor(textField); tree.setEditable(true);/*from w w w. j a va 2 s . c o m*/ tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeEdit.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" }; // Hello will map to false JTree tree = new JTree(array); tree.setEditable(true);//from w ww . j a v a 2 s . c o m tree.setRootVisible(true); JCheckBox checkBox = new JCheckBox(); TreeCellEditor editor = new DefaultCellEditor(checkBox); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Tree Tips"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(new String[] { "a", "b", "c" }); ToolTipManager.sharedInstance().registerComponent(tree); TreeCellRenderer renderer = new ToolTipTreeCellRenderer(); tree.setCellRenderer(renderer);/* w w w . j av a2s. c om*/ JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
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 w w . j ava 2s .com*/ 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[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Properties props = System.getProperties(); JTree tree = new JTree(props); JComboBox comboBox = new JComboBox(new String[] { "A", "B", "C" }); TreeCellEditor editor = new DefaultCellEditor(comboBox); tree.setEditable(true);/* w ww . ja v a 2 s . c o m*/ tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeEdit.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" }; JTree tree = new JTree(array); tree.setEditable(true);/* ww w. ja v a 2 s .co m*/ tree.setRootVisible(true); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); String elements[] = { "A", "B", "C", "D" }; JComboBox comboBox = new JComboBox(elements); comboBox.setEditable(true); TreeCellEditor comboEditor = new DefaultCellEditor(comboBox); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }