JTable: Set cell editable or not based on value of another cell

I want to enable/disable a table cell based on the contents of another cell. e.g. if the reference cell value is "true", then enable the cell, otherwise disable the cell. I have set up isCellEditable() to do this and it works if the reference cell already has a value when bringing the table up. But if the user changes the value, isCellEditable() does not get called and so the cell is not enabled/disabled. So I need to have isCellEditable() called when the reference cell value changes and use that to set the cell. something like:

setCellEditable(isCellEditable(row,column), row, column)

but I don't see a method like setCellEditable.
How is this done?

@Override
public boolean isCellEditable(int row, int column) {

if (column == 3) {
	String value = (String) defaultTableModel.getValueAt(row, 3);
	if (value.equalsIgnoreCase("true")) {
		return true;
	}
	return false;
}
}

Open in new window

LVL 1
allelopathAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
you need to fire an event indicating the cell has changed when the dependant cell changes.
you can do that when you update the dependant cell or create a TableModelListener that does it
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
allelopathAuthor Commented:
I already have the event. The value in (row,3) is changed, for example, from true to false, now I need to disable the cell at (row, 4).  isCellEdtiable() has the capability necessary but I don't see how to call as I cannot find a setCellEditable() method.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.