• 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

JCheckBox in JTable not working

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a JTable that has a JCheckBox in column 2. The checkbox seems to be working okay except I can't seem to be able to check it or uncheck it. It seems to be un-editable. Can someone please look at my code and let me know where I went wrong?
Here's the table model:


Here's the editor:


Renderer:



And here's where I'm creating it all:


I really appreciate any help you can give me

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you have a lot of custom code there. Have you narrowed down what part of the code is causing the problem?

It is the TableModel, the editor or the renderer or something else?

You start by creating a table using the DefaultTableModel with hard coded data such that the check box is working properly. Then maybe you add your custom renderer and see what happens, and then the editor, then you try the custom model etc, etc.. Once you know which customization is causing a problem you can post a demo program showing the problem.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm curious as to why you think you need a custom cell editor for a checkbox. By default Boolean model properties are rendered as checkboxes.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the nudge in figuring this issue out. I've got it working now. I did not have the "setValueAt" method implemented in my table model. Once I did this then I was able to edit the cell.
Thanks again!
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gregg,
This is the first time I have done an editable JTable with a check box. I googled some stuff on the internet and found an example from a forum on Sun's website that showed this was the way to do it. Since my curiosity was sparked from your post I removed the custom cell editor and it still works perfectly! Thanks for the input!
 
reply
    Bookmark Topic Watch Topic
  • New Topic