Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How to make only some rows editable in a JTable

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic