Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes Checkboxes with JTables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Checkboxes with JTables" Watch "Checkboxes with JTables" New topic

Checkboxes with JTables

Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
The way the documentation reads, if a Boolean value is sent to a cell. That cell automatically renders a Checkbox. I am NOT getting that.
Vector data = new Vector();
What is the trick here?
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

Hi Bill,
I'm only going on memory here (since I'm too lazy to verify it ;-), but if you look at the code for the "JTable" class (available in the "src.jar" -- or "" -- file that comes with the J2SE SDK), you will see that the "Class" of the "JTable" column determines what renderer will be used. Therefore, the "getColumnClass()" method (in "javax.swing.table.TableModel" interface) needs to return "Boolean.class" in order to use the "JCheckBox" renderer.
Hope this helps.
Good Luck,
I agree. Here's the link:
subject: Checkboxes with JTables
It's not a secret anymore!