This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Jtable boolean checkboxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable boolean checkboxes" Watch "Jtable boolean checkboxes" New topic
Author

Jtable boolean checkboxes

matt prowell
Greenhorn

Joined: Jul 12, 2004
Posts: 18
I have a column in a Jtable which is boolen. I have a verify button that take you to a new screen I want to display just the rows that have a check in the box (boolean = true). My jtable data is in a vector. Thanks for any help!
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
Hi, Matt -

Could you post a more specific question? Perhaps even let us know how far you've progressed on your design? If you post any code, please be sure to enclose the code in CODE UBB tags, which you can insert using the Instant UBB Code buttons below the Post A Reply section...


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by matt prowell:
My jtable data is in a vector.

Do u mean your data is a vector of objects which represent rows in JTable? If so, you need to check using the index number(location) of the boolean variable in your data. Like Jeff suggests, if you can provide us with a portion of your code, it is more likely that we can help you more...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
At the 1st glance i see 2 possible approaches: either you filter yourself the vector providing the widget with a vector containing only the displayable info, or you code a custom cellrenderer/celleditor. But as cause you are saying you don't want to display anything for the rows with value false, than I guess the first solution is suited.

--
./pope
[the_mindstorm]


blog - InfoQ.com
matt prowell
Greenhorn

Joined: Jul 12, 2004
Posts: 18
I don't have any code yet on filtering the true rows. I got stuck on what to do. Here is some code of how my data is in the vector.

Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
I'm not so sure, if my understanding on your application logic is correct. You might want to check the boolean value of your first element(as I see in your code) and add according to the value of it into the data vector... Have a look at the bolded lines...

One mistake might be that you are adding false value for all of the rowData's first element, which will make your data vector not containing any rowData... It might be a bug...

matt prowell
Greenhorn

Joined: Jul 12, 2004
Posts: 18
Well the code i had displayed was the setup before it was displayed to the user. That is why it was set to false. I want to get the ones the user selects true by checking the box. I did the if statement you said which made sense to me now but I get an error with it.



the data vector is the one that is displayed in the table.

Here is the error I get

project.java [199:1] cannot resolve symbol
symbol : variable booleanValue
location: class java.lang.Boolean
if(((Boolean)data.elementAt(0)).booleanValue == true)
^
1 error


Thanks.
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
booleanValue is a method and not a field :-).

--
./pope
[the_mindstorm]
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Yikes!

It should be if(((Boolean)data.elementAt(0)).booleanValue() == true)

It should work well, if you insert a pair of parentheses like that....
matt prowell
Greenhorn

Joined: Jul 12, 2004
Posts: 18
Thanks that cleared that up. I now get a ClassCastException error. here is the code in my verify class

Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
It is always easier to find a problem when it is expressed correctly. If you provide the exception and its stacktrace, the data you are using and so on, it will be easier .

--
./pope
[the_mindstorm]
matt prowell
Greenhorn

Joined: Jul 12, 2004
Posts: 18
java.lang.ClassCastException
at project.verify(project.java:202)
at project.actionPerformed(project.java:328)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5134)
at java.awt.Component.processEvent(Component.java:4931)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1590)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)



Sorry.
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
As far as i can imagine *data* should be a vector of rows (vector of vectors) and so the data.elementAt(0) is not a Boolean.

--
./pope
[the_mindstorm]
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Ali Pope:
As far as i can imagine *data* should be a vector of rows (vector of vectors) and so the data.elementAt(0) is not a Boolean.


Ali is right, matt... As I added some codes for you above, data is the vector which contains rowData vector... Then that rowData vector contains the first element as a boolean... So you need to check nestedly inside your rowData vector about the boolean value...

Not the first element of data vector... The first element of data vector is still rowData vector... So you need to change your application logic to fetch the value of the first element from rowData vector of data vector...

Hope my explanation helps...
matt prowell
Greenhorn

Joined: Jul 12, 2004
Posts: 18
okay thanks. I will have to try and think how to do this.
matt prowell
Greenhorn

Joined: Jul 12, 2004
Posts: 18
I tried this but I get an error with it. Is that on the right track. Thanks.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtable boolean checkboxes
 
Similar Threads
JTable
JTable
JTable
JTable
JTable