Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

adding a JCheckBox in a JTable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Report post to moderator


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.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic