• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Sara Jones
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!