wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes adding JCheckBox in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "adding JCheckBox in JTable" Watch "adding JCheckBox in JTable" New topic
Author

adding JCheckBox in JTable

siva murugan
Greenhorn

Joined: Feb 14, 2003
Posts: 2
HI All,
Iam facing the following problems in Java Swing while using JTable..
I have a JTable with 11 colums and i add row on run time..
Since i needed the 11th column of the table to be of type CheckBox i used the follwing object in the DefaultTableModel class..
Object[][] data =
{
{"1", "", "", "", "", "", new Double(0.0), new Integer(0), new Double(0.0), new Double(0.0),new Boolean(false) }
};
When ever i wan't to delete a row i will click the Boolean Object ( which appears as a Check box ) and then delete that row.. For deleteing i am using 2 methods..
1. By selecting the col by mouse and the click a button to delete the selected rows...
2. By selecting the col by key board , using a Menu ShortCut key ( CTRL-F ) and then using the space key to on the value , then i use another Menu ShortCut key ( CTRL-D ) to delete all the selected rows..
The above 2 methods work fine as for as deleting is concerned..
But the problem starts while adding another row after deleting one or more rows..That 2 happens while the deletion had been done by the KEYBORD only..

The problem is...
If there is more than 1 rows and i select some rows of any order..And then delete them with the Keyboard option..and then add a rows , while adding the row @ the postion where the last row was deleted iam getting the 11th col. value ( which apears as a check box ) as selected..For example if there is 4 rows and i delete the 3rd and 4th row and then when i add rows its fine for the 3rd row and for the 4th row ( which was the last one which was slected to be deleted ) i get the option as a selected one..
But while adding i use the above said Data object only..I then used the the
JTablename.getValueAt(i,10); to print the value and iam geting false only..
And more over when i try to focus in the cell in 1st row last column of the table by the setSelection method , the focus goes to the cell which appears to be enbled..
My friends asked me to use the follwing methods before adding rows ..
1. clearSelection()

2. Validate()
3. repaint()
But the problem seems not over can anyone help....
U can mail me to k_siva_murugan@yahoo.com
Love,.
Siva
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding JCheckBox in JTable