JTable Combo Box Row Selection Problem
I have a problem with my Table in the project. I have 10 Columns in the Table, the 4th and 10th column are significant to explain this problem.
In the 10th column I have a combo box and in the 3rd Column I have a TextBox. The values for the Text Box is dependent directly on the values of the corresponding row Combo Box using some logical Lookup as shown in the enclosed if (row != -1) loop of the below function.
Code:
myComboofColumn9 = new TableCellCombo(detailTable) {
public void setSelectedItem(Object item) {
super.setSelectedItem(item);
int row = detailTable.getSelectedRow();
System.out.println("rowvalue is : "+row);
if (row != -1) {
TableCellValue value = (TableCellValue) (detailTable
.getValueAt(row, 9));
String id = value.getId();
Vector kQs = ResourceLOVS.getInstance().getKq();
Iterator iter = kQs.iterator();
LovObject lov;
while (iter.hasNext()) {
lov = (LovObject) (iter.next());
if (lov.getId().equals(id)) {
detailTable.setValueAt(new TableCellValue(lov
.getRule()), row, 3);
break;
}
}
}
}
};
The first time I select a myComboofColumn9 of a particular row my rowvalue is the correct Row. Lets say I selected the 2nd row. So it prints 1 (as row indexes start from 0)
Now Lets say I just click on the rightmost part of the myComboofColumn9 of row 3 and not select anything (as in by clicking just the arrow and leaving it thereby combo just appears and disappears), setselected item is called this time printing 2 again and not 3. So my logic is run and Row 2 Text Box value is changed and not the 3rd.
This goes on as I switch, every time selecting one row older. I suspect that because the older combo box is still highlighted. How do I make this work.