Only 49 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create Table with Checkbox  RSS feed

 
K.Suresh Kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to create a table and placed the check box in the first column of the table. Please any one tell me how to create? and how to identify whether the check box is selected or not. Give me guidelines or sample codes.


Thanks & Regards,
Suresh Kumar.K
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What TableModel are you using?

Let's assume you are using DefaultTableModel. What you should then do is have its class for the first column be Boolean.class:

This will then automatically use a check box for both showing and editing. The value can be retrieved using getValueAt:


There are a few more classes returned by getColumnClass that are automatically recognized:
- Number and its classes (Integer, Long, Float, etc) will be right-aligned
- Icon and ImageIcon will show an image
- Date will use DateFormat.getDateInstance() for showing

The latter will use the Date(String) constructor to create Date objects from the text you enter. It is therefore quite strict in the format, something I think is a mistake. You can search this forum for a solution I posted that can use any DateFormat.


You can always call setDefaultRenderer and setDefaultEditor on your table to use a renderer / editor for all columns of your class. How this works:
1) if there is a renderer for the class returned by getColumnClass that will be used
2) if not, that class' superclass is checked
3) if not, see 2

So for example, if your model returns Integer.class, it first checks the renderer set for Integer.class. If there is none, Number.class is checked. If there is still none, Object.class is checked.
 
K.Suresh Kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your kindly help.It works fine.
Sorry after a long holiday i came to my office today.So that i didn't reply to your help.

Thanks,
Suresh Kumar.K
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!