0

my problem is that when I put Object to table in cell with CellEditor set to work as JComboBox and it's fine, but when click on the cell i got list with Objects, but selected one is not that which were in cell before, but just first on the list. Is there simple way to fix it?

public void setValueAt(Object value, int row, int col) {
    data.get(row).values.set(col, (Device) value);
    fireTableCellUpdated(row, col);
}

and

for(int i = 0; i < deviceTable.getModel().getColumnCount(); i++){

        ExtendedAbstractTableModel model = (ExtendedAbstractTableModel) deviceTable.getModel();

        JComboBox<Device> combo = new JComboBox<Device>();

        for(Device value : model.columnsCombo.get(i)){
            combo.addItem(value);
        }

        TableColumn columnModel = deviceTable.getColumnModel().getColumn(i);
        columnModel.setCellEditor(new DefaultCellEditor(combo));
}
Naix
  • 17
  • 6

2 Answers2

1

As shown in this example, DefaultCellEditor handles this for you. You're adding multiple instances in a loop; a single instance can handle the entire column. DefaultCellEditor works by overriding setValue() in the nested EditorDelegate. It's not clear how you've defeated this feature, but understanding the default may guide your search.

public void setValue(Object value) {
    comboBox.setSelectedItem(value);
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

Finally I found what was wrong. I didn't override equal method in my class, and that is why these components couldnt recognise same item. Anyway, thank you all.

Naix
  • 17
  • 6