I am trying to add unique JComboBoxes
to a column in a JTable
. I know it is possible to add a JComboBox
to an entire column using
Try this:
...
final Object[] obj = {"test1", "test2", "test3"};
JTable jTable = new JTable();
TableColumn column = jTable.getColumnModel().getColumn(1);
column.setCellEditor(new AutoCompletionComboBoxEditor(obj));
...
public static class AutoCompletionComboBoxEditor extends AbstractCellEditor implements TableCellEditor {
JComboBox cbx;
public AutoCompletionComboBoxEditor(Object[] items) {
cbx = new JComboBox(items);
}
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
return cbx;
}
public Object getCellEditorValue() {
return cbx.getSelectedItem();
}
}
try tell me the effect :)
-Saligh