This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes adding a JCheckBox in a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply locked New topic
Author

adding a JCheckBox in a 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
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

I have a JTable with 11 colums and i add row on run time..

Here we go again. Yet another version of the developer assignment...
Eugene.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

This is not a question regarding the SCJD exam. I am closing this thread.
Also this is a duplicate post.
Please try to refrain from cross-posting the same question to more than one forum.
I know you are new here Siva, and sometimes new people aren't familiar with some of our rules, so we'll let you slide on this one.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding a JCheckBox in a JTable
 
Similar Threads
JTable
Jtable combo box issue
Multiple selection in JTable
adding JCheckBox in JTable
jtable