I have a problem anyone can help me. This is my JTable
and one column rendered in it have a combo box in its cell. Here is my problem in my table: it wont popup when I click the combo box. When I print, table.getValueAt(row,column)
, it will get back the prev data of the cell not the data in combo box, and it doesn't show the combo box to let the user choose.
The code of the JTable
:
public void setUpSportColumn(JTable table, TableColumn sportColumn) {
// Set up the editor for the sport cells.
JComboBox<String> comboBox = new JComboBox<String>();
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
model.addElement("Snowboarding");
model.addElement("Rowing");
model.addElement("Knitting");
model.addElement("Speed reading");
model.addElement("Pool");
model.addElement("None of the above");
comboBox.setModel(model);
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
ComboBoxTableCellRenderer renderer = new ComboBoxTableCellRenderer();
renderer.setModel(model);
sportColumn.setCellRenderer(renderer);
}