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: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  ww  w.  j av a 2  s .co  m

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

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

    comboEditor.getCellEditorValue();

    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 w w .  j a  va  2s. c  om

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

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

    comboEditor.setClickCountToStart(3);

    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 w w  .  jav a2  s  .co m

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

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

    System.out.println(comboEditor.getComponent());

    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   www.  j  a v  a 2 s. c  o m*/

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

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

    System.out.println(comboEditor.getClickCountToStart());

    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(String[] args) {
    String[] m = { "A", "B", "C" };
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(new Node("Values"));
    root.add(new DefaultMutableTreeNode(new Node("Value 1", m)));
    root.add(new DefaultMutableTreeNode(new Node("Value 2", m)));
    DefaultMutableTreeNode leaf = new DefaultMutableTreeNode(new Node("Value 3", m));
    root.add(leaf);//from  w  w w . j  ava2s  . c  o  m
    leaf.add(new DefaultMutableTreeNode(new Node("Value 3A", m)));
    leaf.add(new DefaultMutableTreeNode(new Node("Value 3B", m)));

    JTree tree = new JTree(root);
    RendererDispatcher rendererDispatcher = new RendererDispatcher(new JComboBox<String>());
    RendererDispatcher editorDispatcher = new RendererDispatcher(new JComboBox<String>());
    tree.setCellRenderer(rendererDispatcher);
    tree.setCellEditor(editorDispatcher);
    tree.setEditable(true);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(tree));
    f.setSize(320, 240);
    f.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  .java2 s  .  co  m

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

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);//from w ww.ja  v  a  2 s.  c o  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);
}

From source file:Main.java

public static JComponent makeUI() {
    JTree tree = new JTree();
    TreeModel model = tree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    Enumeration e = root.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        Object o = node.getUserObject();
        if (o instanceof String) {
            node.setUserObject(new CheckBoxNode((String) o, false));
        }/*from   w w w.  ja v a  2 s. c o  m*/
    }
    tree.setEditable(true);
    tree.setCellRenderer(new CheckBoxNodeRenderer());
    tree.setCellEditor(new CheckBoxNodeEditor());
    tree.expandRow(0);
    return new JScrollPane(tree);
}

From source file:MyData.java

public Main() {
    super();//  ww w .  j av a2s  . c  om
    JTree tree = new JTree(getRootNode()) {
        public boolean isPathEditable(TreePath path) {
            Object comp = path.getLastPathComponent();
            if (comp instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) comp;
                Object userObject = node.getUserObject();
                if (userObject instanceof Main) {
                    return true;
                }
            }
            return false;
        }
    };
    QuestionCellRenderer renderer = new QuestionCellRenderer();
    tree.setCellRenderer(renderer);
    QuestionCellEditor editor = new QuestionCellEditor();
    tree.setCellEditor(editor);
    tree.setEditable(true);
    JScrollPane jsp = new JScrollPane(tree);
    getContentPane().add(jsp);
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

private void addTreeSelectionListener(JTree theTree) {
    if (theTree == null) {
        return;/*ww  w  .  j av  a  2s  . c o m*/
    }
    trees.add(theTree);
    theTree.setCellEditor(new DepositTreeEditor(theTree, new DefaultTreeCellRenderer(), new DefaultCellEditor(
            new TreeEditorField(applicationProperties.getApplicationData().getMaximumStructureLength()))));
    theTree.setUI(new CustomTreeUI());
    theTree.setCellRenderer(new IconRenderer(currentIconDirectory));
    theTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
        public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
            treeValueChanged(evt);
        }
    });
}