How can I disable selection of ("grey out") several cells in a column of a JTable according to the value of the cells?
Created May 7, 2012
Scott Stanchfield
You can "disable" the cells by setting "enabled" to false in your table cell renderer. For example:
public class MyTCRenderer
extends JLabel
implements TableCellRenderer {
public Component getTableCellRendererComponent(
JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column) {
if (value.equals("disable me")) {
setEnabled(false);
}
else
setEnabled(true);
setText((String)value);
// other stuff...
}
}