Skip to content
Advertisement

JTable -> TableModeListener

I have this JTable having a DefaultTableModel as its model. On the table I have several swing component, JComboBox and JCheckBox, set on a particular column via DefaultCellEditor and DefaultCellRenderer. The TableModelListener was added to the table to capture changes on editable columns. The rest of the columns will display details of the selected component, i.e. item code -> item price, item count, item classification,etc.

I have this problem wherein if the selectedItem of the JComboBox(itemCode) changes, the items of the other JComboBox(itemClassification) changes. But together with the change of the other JComboBox I need to display the item price on the same table. This change refires the valueChanged method which makes an infinite loop of valueChanged.

How can I get rid of the infinite loop thing?

Advertisement

Answer

One way is to check the update event to see what column the event is for and ignore columns that are automatically updated:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement