Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make only some rows editable in a JTable

 
sandhya raviprasad
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a JTable with 4 columns and 8 rows. One of the columns has checkboxes with true - false values indicating that if the value of the checkbox is true, then that row should be uneditable, if the cb value is false, then the row should be editable. Please guide me with this.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way that I can think of to do it is to add a Listener to the table. When any KeyEvent occurs look at the checkbox, and if it is set to true, then get rid of the keystroke.
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sandhya,
to make few rows editable u need to override boolean isCellEditable(int row,int column) method of JTable class.


actually whenever you try to edit some cell then the method isCellEditable() is fired for that row,col pair. so u can override this method to return true/false depending on whatever conditions u have.
hope that was clear.
regards
deekasha


regards
deekasha
 
Sandhya Rprasad
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi deekasha
Thanks, but I'd already solved the problem. But I guess, I picked up on the same thing as u've suggested. Thanks a lot.
I'd really appreciate it if I could get a little fast response.
regards
Sandhya
 
eric moon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Sandhya, instead of complaining, how about answering your own question when you figure it out, so others don't spend their time and energy answering it.
That's what I do. After all, we don't pay to use JavaRanch!
 
Sandhya Rprasad
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by eric moon:
Well, Sandhya, instead of complaining, how about answering your own question when you figure it out, so others don't spend their time and energy answering it.
That's what I do. After all, we don't pay to use JavaRanch!

Hi Eric
It was not a complain, but it was a suggestion. I'm sorry if you could'nt get to the sensitivity of the solution. If you did observe, I did thank Deekasha for the response which I certainly mean. Ofcourse I am aware that we don't pay JavaRanch to use it and yes, I did find the solution after a lot of struggle and research over the net and stuff. Yes, if the solution given to me did'nt help me much in time, which I'm not blaming, it may help someone else coming up with similar problems in the future.
So, please do put your words after giving it a serious thought when you're posting on such forums .. I'd really appreciate that !!!
Sandhya

 
Gary F.
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, thanks that helped, I new how to get the rows/cols to to enabled are start, but was having trouble with the checkbox and getting thoughs rows only to be editable, with the code provided about it gave me anouther idea.
So thanx for the inital posting and all the replies. , this will help me no my class final project 60% of sem grade
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic