Example usage for javax.swing JTree setCellEditor

List of usage examples for javax.swing JTree setCellEditor

Introduction

In this page you can find the example usage for javax.swing JTree setCellEditor.

Prototype

@BeanProperty(description = "The cell editor. A null value implies the tree cannot be edited.")
public void setCellEditor(TreeCellEditor cellEditor) 

Source Link

Document

Sets the cell editor.

Usage

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);//w  ww.  jav  a  2  s.c  om
    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);/*w  ww .j  a 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: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. ja  v  a  2 s  .  co  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: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   ww  w .  j  av  a  2 s.  com*/
    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: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);//  www .j  a  v a  2  s  . com
    tree.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:EditLeafSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Editable Tree");
    JTree tree = new JTree();
    tree.setEditable(true);/*from   w  ww .  jav a 2  s .  co m*/

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
    TreeCellEditor editor = new LeafCellEditor(tree, renderer);
    tree.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    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);
    JTree tree = new JTree();
    tree.setEditable(true);/*from   w w  w  .  java  2s  . c o m*/

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();

    TreeCellEditor comboEditor = new DefaultCellEditor(new JTextField());
    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);
}

From source file:CheckBoxNodeTreeSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("CheckBox Tree");

    CheckBoxNode accessibilityOptions[] = {
            new CheckBoxNode("Move system caret with focus/selection changes", false),
            new CheckBoxNode("Always expand alt text for images", true) };
    CheckBoxNode browsingOptions[] = { new CheckBoxNode("Notify when downloads complete", true),
            new CheckBoxNode("Disable script debugging", true), new CheckBoxNode("Use AutoComplete", true),
            new CheckBoxNode("Browse in a new process", false) };
    Vector accessVector = new NamedVector("Accessibility", accessibilityOptions);
    Vector browseVector = new NamedVector("Browsing", browsingOptions);
    Object rootNodes[] = { accessVector, browseVector };
    Vector rootVector = new NamedVector("Root", rootNodes);
    JTree tree = new JTree(rootVector);

    CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
    tree.setCellRenderer(renderer);/*w  ww.  j  ava 2  s.  c o m*/

    tree.setCellEditor(new CheckBoxNodeEditor(tree));
    tree.setEditable(true);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    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);
    JTree tree = new JTree();
    tree.setEditable(true);/* w  w w.ja  va2 s.  c o  m*/

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();

    DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField());

    comboEditor.stopCellEditing();

    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);
}

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Editable Tree");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTree tree = new JTree();
    tree.setEditable(true);//from  w ww.  j  a va  2s  . c o  m

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();

    DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField());

    comboEditor.cancelCellEditing();

    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);
}