File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Problem  in checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem  in checkbox" Watch "Problem  in checkbox" New topic
Author

Problem in checkbox

supriya acharya
Greenhorn

Joined: Jan 26, 2009
Posts: 28
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

Joined: Oct 27, 2005
Posts: 19693
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

Change your code to this



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

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

Joined: Jan 26, 2009
Posts: 28
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

Joined: Jul 26, 2007
Posts: 10360
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
supriya acharya
Greenhorn

Joined: Jan 26, 2009
Posts: 28
Thanks

I have done it by using tablecellrenderer..Thanks for the reply
seema chhetri
Ranch Hand

Joined: Feb 17, 2009
Posts: 42
[MG] Removed thread hijack content
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10360
    
    8

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in checkbox