Reputation: 11
Below is the picture of my table. Columns Unit
and Description
have ComboBox
editors. I have added an item listener for the Description
column that when I select a different item, the items for Unit
column will also be changed.
My problem is there are instances that for other rows of the table, it will have a different description. And the Unit
column for that row will also have different items compared to the previous row.
How can I populate the ComboBox
for Column A when ComboBox
for Column B is changed, for that row only?
Upvotes: 1
Views: 726
Reputation: 347184
Start by having a look at Concepts: Editors and Renderers and Using Other Editors
The general answer is, you need two editors, when TableCellEditor#getTableCellEditorComponent
is called, you would use the JTable
reference and the row
/column
properties to look up the current value of column B
and update the values of editor you return via the method
Now, if you want to change the value of column A
based on changes to column B
, you would need to look at the TableModel#setValueAt
method, which will be called when the values are changed for any cell and modify A
based on the current value of B
Upvotes: 2