Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes JTable+JCheckBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable+JCheckBox" Watch "JTable+JCheckBox" New topic


francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 166
Dear Sirs,
I have a Jtable, and a cloumn with boolean type which is represented by
a checkbox, however the checkbox doesn't show to solve this?

the code is like ,

model=new DefaultTableModel(head,0);
table=new JTable(model);
JScrollPane scroll=new JScrollPane(table,v,h);?
check_box=new JCheckBox("Select",false);
dropDownColumn = table.getColumnModel().getColumn(9); dropDownColumn.setCellEditor(new DefaultCellEditor(check_box));
Brian Cole
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Since you are using new DefaultTableModel(head,0),
you must be adding these boolean values later, right?

It is possible to get the checkbox to show in the table
by messing with cell renderers and cell editors. Your
code doesn't do anything with renderers, hence they
don't show. (If you click in column #9 you should see
your editor, though I haven't tried it.)

However, the easy way to do this is just to make sure
you are returning Boolean.class for column #9 in your
table model's getColumnClass() method. For you, this
means subclassing DefaultTableModel, perhaps anonymously.
This will give you your checkbox without having to mess
with cell renderers or cell editors.

bitguru blog
jQuery in Action, 2nd edition
subject: JTable+JCheckBox
Similar Threads
JTable problem
JTable -background color
Images in a JTable
JCheckBox in JTable