• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 943
  • Last Modified:

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?

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

1 Solution
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
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now