• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checkbox in JTable wont appear checked?

 
Ranch Hand
Posts: 54
Android
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Rancher
Posts: 3324
32
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the Swing tutorial on Creating a 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.
 
Sean Michael Hayes
Ranch Hand
Posts: 54
Android
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I'm thick....

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.

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Uh oh! I see a Null Pointer exception if your rowList is empty
 
Sean Michael Hayes
Ranch Hand
Posts: 54
Android
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sean Michael Hayes
Ranch Hand
Posts: 54
Android
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic