Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable boolean checkboxes

 
matt prowell
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
matt prowell
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
booleanValue is a method and not a field :-).

--
./pope
[the_mindstorm]
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that cleared that up. I now get a ClassCastException error. here is the code in my verify class

 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay thanks. I will have to try and think how to do this.
 
matt prowell
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this but I get an error with it. Is that on the right track. Thanks.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic