• 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

Table with a Checkbox column, unabe to persist the change in values

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a table with 4 columns, out of which the 4th column is a checkBox column. I have used an DefaultCellEditor to edit this column. The problem I am facing is that, when ever I edit the checkbox on the 1st row, it discplays with a tick. But as soon as I check any of the other rows withtin the same column, the previous tick has been lost. How do I persist the value in this case ?


Where UpdateRecord is my custom method where I am writing the data to the database.

Please help me with this one asap.

Thanks in advance.
Sara
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this link is "how to use tables", with demo sample code containing a checkbox column

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

add your update(true/false) code to the above (can be to just do a system.out.println),
and if the checkbox state persists, compare your code to that of the demo to see what's different
 
Sara Jones
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. But I have already gone through the table tutorial that you sent. But it was not much help for me since it gives a generic example of how to create column with checkboxes. It would be really helpful if I could get to know what is missing in the code that I pasted for the value to be persisted, infact multiple selection on different rows on the same column should be possible.

Thanks.
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd drop the custom check box renderer / editor combination, and use Swing's own mechanism for this:
- let your TableModel return Boolean.class for that column; the values should of course be Boolean objects as well
- let the JTable use its default renderer / editor for that, which will already be a check box because of the previous
- use a TableModelListener to listen for changes to cell values

Alternatively to the last step, you can override your TableModel's setValueAt method:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic