Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enabling and disabling single cell in JTable

 
Mahesh Kedari
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 ?
 
pete stein
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java 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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic