Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable+JCheckBox

 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sirs,
I have a Jtable, and a cloumn with boolean type which is represented by
a checkbox, however the checkbox doesn't show properly.how to solve this?


the code is like ,

model=new DefaultTableModel(head,0);
table=new JTable(model);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
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
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic