Example usage for javax.swing.table TableColumn setCellEditor

List of usage examples for javax.swing.table TableColumn setCellEditor

Introduction

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

Prototype

@BeanProperty(description = "The editor to use for cell values.")
public void setCellEditor(TableCellEditor cellEditor) 

Source Link

Document

Sets the editor to used by when a cell in this column is edited.

Usage

From source file:ChooserTableSample.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Editable Color Table");
    TableModel model = new ColorTableModel();
    JTable table = new JTable(model);

    TableColumn column = table.getColumnModel().getColumn(3);

    ComboTableCellRenderer renderer = new ComboTableCellRenderer();
    column.setCellRenderer(renderer);//from   w w w. j  av a 2  s.co  m

    TableCellEditor editor = new ColorChooserEditor();
    column.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void insertComponentInColumn(JTable jTable, int col, JComponent jComponent) {
    TableColumn sportColumn = jTable.getColumnModel().getColumn(col);
    if (jComponent instanceof JComboBox) {
        sportColumn.setCellEditor(new DefaultCellEditor((JComboBox) jComponent));
    } else if (jComponent instanceof JCheckBox) {
        sportColumn.setCellEditor(new DefaultCellEditor((JCheckBox) jComponent));
    } else if (jComponent instanceof JTextField) {
        sportColumn.setCellEditor(new DefaultCellEditor((JTextField) jComponent));
    }// w  ww .  j a  v  a  2  s  .co m
}

From source file:OAT.ui.util.UiUtil.java

public static void addComboCell(TableColumn column, Object[] items) {
    column.setCellEditor(new DefaultCellEditor(new JComboBox(items)));
}

From source file:GenderEditor.java

public TableCellEditorJComboBox() {
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());
    TableValues tv = new TableValues();
    table = new JTable(tv);
    TableColumnModel tcm = table.getColumnModel();
    TableColumn tc = tcm.getColumn(TableValues.GENDER);
    tc.setCellEditor(new GenderEditor());
    JScrollPane jsp = new JScrollPane(table);
    pane.add(jsp, BorderLayout.CENTER);
}

From source file:TableCellRenderTest.java

public TableCellRenderFrame() {
    setTitle("TableCellRenderTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    TableModel model = new PlanetTableModel();
    JTable table = new JTable(model);
    table.setRowSelectionAllowed(false);

    // set up renderers and editors

    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Color.class, new ColorTableCellEditor());

    JComboBox moonCombo = new JComboBox();
    for (int i = 0; i <= 20; i++)
        moonCombo.addItem(i);// ww  w. java 2s . c  o  m

    TableColumnModel columnModel = table.getColumnModel();
    TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN);
    moonColumn.setCellEditor(new DefaultCellEditor(moonCombo));
    moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class));
    moonColumn.setHeaderValue(new ImageIcon("Moons.gif"));

    // show table

    table.setRowHeight(100);
    add(new JScrollPane(table), BorderLayout.CENTER);
}

From source file:TableRenderDemo.java

public void setUpSportColumn(JTable table, TableColumn sportColumn) {
    // Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Snowboarding");
    comboBox.addItem("Rowing");
    comboBox.addItem("Knitting");
    comboBox.addItem("Speed reading");
    comboBox.addItem("Pool");
    comboBox.addItem("None of the above");
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));

    // Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    sportColumn.setCellRenderer(renderer);
}

From source file:components.TableRenderDemo.java

public void setUpSportColumn(JTable table, TableColumn sportColumn) {
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Snowboarding");
    comboBox.addItem("Rowing");
    comboBox.addItem("Knitting");
    comboBox.addItem("Speed reading");
    comboBox.addItem("Pool");
    comboBox.addItem("None of the above");
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));

    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    sportColumn.setCellRenderer(renderer);
}

From source file:logdruid.ui.table.EventRecordingEditorTable.java

public void setUpProcessingColumn(JTable theTable, TableColumn typeColumn) {
    JComboBox functionComboBox = new JComboBox();
    functionComboBox.addItem("capture");
    functionComboBox.addItem("duration");
    functionComboBox.addItem("occurrences");
    functionComboBox.addItem("sum");
    typeColumn.setCellEditor(new DefaultCellEditor(functionComboBox));
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    typeColumn.setCellRenderer(renderer);
}

From source file:com.frostwire.gui.library.LibraryDeviceTableMediator.java

protected void setDefaultEditors() {
    TableColumnModel model = TABLE.getColumnModel();
    TableColumn tc;

    tc = model.getColumn(LibraryDeviceTableDataLine.TITLE_IDX);
    tc.setCellEditor(new LibraryNameHolderEditor());
}

From source file:logdruid.ui.table.StatRecordingEditorTable.java

public void setUpTypeColumn(JTable theTable, TableColumn TypeColumn) {
    // Set up the editor for the Type cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("word");
    comboBox.addItem("string");
    comboBox.addItem("long");
    comboBox.addItem("double");
    comboBox.addItem("date");
    comboBox.addItem("percent");
    TypeColumn.setCellEditor(new DefaultCellEditor(comboBox));

    // Set up tool tips for the Type cells.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    TypeColumn.setCellRenderer(renderer);
}