I want to add checkbox in a table column. I used following code for this.
I am able to get checkboxes in a column....but the issue is ... they are not selectable i.e. I am not able to tick them...
Also, I would like to know how we can get row value for which checkbox is checked ??
Thanks ,
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
try the sample code from the sun site 'how to use tables',
one of the columns is a (selectable/tickable) checkbox
But since I am very new to Swings, was unable to modify that code as per my requirement .. tried a lott ... My requirement is very simple.. There are 2 columns in a table .. 1st -> Checkbox ... 2nd -> Name .. and there is one button (OK).. Onclick of button OK ... I want a list which contains values (Names) for which checkbox is checked ... It's very basic requirement ... It would be really helpful if someone provide sample code for this ..
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1791
2
posted
0
I want a list which contains values (Names) for which checkbox is checked ...
1) Create a loop
2) use the model.getValueAt(...) method to get the value from the column containing the Boolean value
3) if ( theValue.equals( Boolean.TRUE ) ) then get the Name from the model using the getValueAt() method for the current row and specific column.
Rite Sara
Ranch Hand
Joined: Feb 13, 2010
Posts: 56
posted
0
I am using the code similar to code posted in previous post and I am getting checkboxes in a table .. but not able to check(click) them ...
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1791
2
posted
0
I am using the code similar to code posted in previous post
I don't see your SSCCE posted anywhere that shows the similiar code. The key is to override the getColumnClass() method of the JTable or the model to return the proper class so the table can choose the proper renderer and editor to use.
Rite Sara
Ranch Hand
Joined: Feb 13, 2010
Posts: 56
posted
0
I don't see your SSCCE posted anywhere that shows the similiar code. .
Here I am posting my code again ...
I am overriding getColumnClass() here.. and I am getting checkboxes in the column ...
But the issue is I am not able to check them .
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1791
2
posted
0
How is your code like the demo code from the tutorial?
Where in the demo code:
a) is a custom renderer used?
b) is a JCheckBox added to the model?
Start with a working example and make changes to the working code 1 at a time. Then if is stops working you know what you changed to cause the problem.
Rite Sara
Ranch Hand
Joined: Feb 13, 2010
Posts: 56
posted
0
This is working example only ... Yes..its from tutorial ...but I have implemeted same way in my code ...
Given below are the steps showing the way I am implementing ...
1st ... I am making object array with checkboxes .. and adding it to model ...