Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

adding JCheckBox in JTable

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • 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
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic