• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

enabling and disabling single cell in JTable  RSS feed

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Is it possible to control enabling and disabling of table at cell level?

I have checked this post, but its partially helpful.

Requirement :
I have a table with 7 columns. If value of 2nd column in specific row is null then all other cells in that rows should be disabled.
But it should not disable other rows in which 2nd column contains valid data.

Could anyone please help me ?
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mahesh Kedari wrote:Hi all,
Is it possible to control enabling and disabling of table at cell level?

I have checked this post, but its partially helpful.


How is it "partially" helpful as it has the key to your problem. Perhaps you should post a small compilable and runnable program that has no outside dependencies (no need for database or files), that illustrates your problem,and that shows how overriding the isCellEditable method doesn't work for you. This type of program is called an SSCCE. Please see this link for more instructions on how to create this: SSCCE link
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks pete for your reply.

Below is the runnable example of my code.



I am adding new row to table if editing row is last row of the table. Here user must select the date first before editing anything else in that row. So i want to disable other cells in that row.
 
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TableModel.isCellEditable takes both a row and column. That allows you to return a value dynamically based on the exact cell. Overriding DefaultTableModel is the easiest:
 
Mahesh Kedari
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Rob for help...!!
Its working fine.
 
Rob Spoor
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!