in my project I've several JComboBox with their custom models. Basically they are used to show values of some JTables column (therefore I decided to implement them on the relative class extending AbstractTableModel).
public class MyTableModel1 extends AbstractTableModel{
protected class MyTableComboBoxModel1 extends AbstractListModel implements ComboBoxModel{
private Object selected;
@Override
public Object getElementAt(int index) {
return getValueAt(index, 1);
}
@Override
public int getSize() {
return getRowCount();
}
@Override
public Object getSelectedItem() {
return this.selected;
}
@Override
public void setSelectedItem(Object anItem) {
this.selected = anItem;
}
}
}
And I have several models : MyTableModel2 with MyTableComboBoxModel2. These models all do pretty the same thing except some additional operations not related neither with the combobox nor with the table itself.
The purpose of all this stuff should be to update JComboBox's displayed values accordingly to modifications occured to the relative JTable.
All works fine for models I've implemented except in one case , and after several hours of debug I still can't solve it. The code of the bugged model is almost identical to the others. Probably it's a bug somewhere else in my code, but I can't figure out where.
The wrong case has the following behavior: when I initially created a table with some values these are correctly displayed even in the JComboBox, but when I add a new row the displayed values become all blank (the size of the displayed blank menu is right). I found out that:
Has someone any idea? Could you suggest me how could I debug in such a situation? Unfortunately I can't post an SSCCE.. I hope someone could help anyway..
I know that my question is a bit vague
Which is why a SSCCE is required.
Each combo box should show all the value of a particular column of an existing JTable
I don't understand why you need a custom model. I would guess you just need to use a TabelModelListener.
Whenever a value is added/removed you updated the combo box.