Example usage for javax.swing DefaultCellEditor DefaultCellEditor

List of usage examples for javax.swing DefaultCellEditor DefaultCellEditor

Introduction

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

Prototype

public DefaultCellEditor(final JComboBox<?> comboBox) 

Source Link

Document

Constructs a DefaultCellEditor object that uses a combo box.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    String headers[] = { "Upper", "Lower" };

    JComboBox comboBox = new JComboBox(rows[0]);
    comboBox.setMaximumRowCount(4);/*  w w  w  . j  a v  a  2s  .c o m*/

    TableCellEditor editor = new DefaultCellEditor(comboBox);

    JFrame frame = new JFrame("JTable Anatomy");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(new DefaultTableModel(rows, headers));

    table.getColumnModel().getColumn(1).setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(table);
    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  v a2  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);/*from   w ww.j  a v  a  2s  . 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:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setSize(450, 250);/*from w  w w.j  ava  2  s. com*/

    JTable table = new JTable(5, 5);

    TableColumn testColumn = table.getColumnModel().getColumn(0);

    JComboBox<String> comboBox = new JComboBox<>();
    comboBox.addItem("This");
    comboBox.addItem("is");
    comboBox.addItem("a");
    comboBox.addItem("Sample program");
    testColumn.setCellEditor(new DefaultCellEditor(comboBox));

    frame.add(table);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    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  ww w.j a  v a2 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);//w  w  w  .j  av  a 2s.  c  om
    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);//from  w w w  . j a  va2 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: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);//  ww w.  j a  va  2s. co 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: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.  j  a  v  a2s . 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(final String args[]) {
    JFrame frame = new JFrame("Editable Tree");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTree tree = new JTree();
    tree.setEditable(true);//  w  ww.  ja v a 2 s . 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);
}