Jesse James
Jesse James

Reputation: 1223

getCellEditorValue() of CellEditor.java is Only Called When the Cell is Clicked

Consider the following Jtable, and more precisely the first column which has a JComboBox in it:

enter image description here

When I try to save the value of the first JComboBox (the one that has "auth2" as its value) without clicking on it first, when I check the database, I find an empty String.

However, when I click on it first and then save, I get the right value stored in the databse.

Using the debugger, I found out that the method getCellEditorValue() of CellEditor.java is only called when you click on the JComboBox itself first.

This explains why in the database, I get the right value when I click on the JComboBox first and when I don't click on it, I get an empty String.

So my question is, is there a way to call the getCellEditorValue() method every time I save, regardless of whether or not I click on the JComboBox?

Thank you

Upvotes: 0

Views: 502

Answers (1)

camickr
camickr

Reputation: 324127

I get the right value when I click on the JComboBox first and when I don't click on it, I get an empty String.

You should NOT try to access a value from the combo box. The combo box is shared as an editor for all rows in the table.

is there a way to call the getCellEditorValue() method every time I save

Data is stored in the TableModel, not the combo box.

You can use the getValueAt(…) method of the JTable or TableModel at any time to get the value from the model.

Note: it is possible (depending on what you are doing) that the data has not been saved from the editor to the TableModel. If this is the case then check out: JTable stop cell editing without user click for solutions.

Upvotes: 1

Related Questions