I have a checkbox in a JTable. This JTable uses an abstractTableModel with each row being populated by an arraylist containing Objects. One value is a boolean value that appears on the table as a checkbox. When I click on this checkbox. The value of the boolean in that particular object changes but its GUI representation does not check/uncheck itself to represent this. Is there something wrong with my setValueAt method in my custom table model?
You can also see Row Table Model for an implementation that uses a List to hold the data. You basically just need to implement the getValueAt() and setValueAt() methods. The JButtonTableModel gives a short example of how to do this.
Turns out the problem was in my GetValueAt method. I had set the boolean value to false in a switch statement. This was during the stage where I just wanted the table to display and then forgot to add logic to it.
Maneesh Godbole wrote:Uh oh! I see a Null Pointer exception if your rowList is empty
The getValueAt method is only called when I pass data into the table and reload it, or am I missing something here? It isn't automatically loaded at the start.
The getValue() will be called whenever the table wants to repaint itself. From a developer's perspective that will be any time after the table is displayed on the UI
Maneesh Godbole wrote:The getValue() will be called whenever the table wants to repaint itself. From a developer's perspective that will be any time after the table is displayed on the UI
Good point, I better make a cover for that. Thanks for the heads up.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.