File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable+JCheckBox" Watch "JTable+JCheckBox" New topic


francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 169
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: 878
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
I agree. Here's the link:
subject: JTable+JCheckBox
jQuery in Action, 3rd edition