File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in checkbox

 
supriya acharya
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

This is my code ..when i set the value of any cell o new Boolean(true) its is showing me true as a string in the table where as i want checkbox which is checked.how can i do that??


 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Please Use Code Tags. I've added them for you; you can see how much better the code looks like

2) Please Carefully Choose One Forum. The Swing forum is a much better place for this thread.


Now, as for your problem:
1) use Boolean.valueOf(bool), or one of the constants Boolean.TRUE and Boolean.FALSE. This way you can use the same two objects (Boolean.TRUE and Boolean.FALSE) instead of creating a new Boolean object each time.

2) check out How to Use Tables. Basically, you need a different renderer for the boolean. You can do it the hard way (create your own renderer) or the easy way: have your TableModel return Boolean.class for that column. JTable has default support for a few classes including Boolean; all you have to do is return the right class from your model.
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change your code to this

 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That won't work either. You'll see the result of a call to toString of the JCheckBoxes.

Using Boolean objects combined with a return of Boolean.class for the column class works best.
 
supriya acharya
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
Thanks for the solution buyt how can i do that by returning boolean.class
can you provide some example code for that?
Thanks

 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you go through the "How to use tables" link provided by Rob? It has example code that you are looking for.
In a nutshell, you need to override your table model's getColumnClass() method to return the appropriate class; by default it returns Object.class.
 
supriya acharya
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

I have done it by using tablecellrenderer..Thanks for the reply
 
seema chhetri
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[MG] Removed thread hijack content
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seema,
Welcome to the Ranch.
Please post your question by starting a new thread.
You can do it by clicking the "New Topic" button on the top right hand corner of this page.
Also please read this
http://faq.javaranch.com/java/UseOneThreadPerQuestion
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic