I'm using a JTable and I only want columns 0 and 3 to be editable. Column 0 works fine, but when I go to edit column 3, it returns true that it is editable, but does not allow me to enter new text or fire setValueAt(...).
I do have some click events, which I remarked out and using a custom renderer, which I disabled, but nothing seems to help. What else should I look at for a problem? It's not throwing any errors.
Do I need to set a cell editor? I've tried some examples I've found but none seem to work properly. Column 0 is a boolean (checkbox, which works fine) and the rest are strings.
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
if (col == 0) {
return true;
}else if(col == 3) {
return true;
} else {
return false;
}
}
/*
* Don't need to implement this method unless your table's
* data can change.
*/
public void setValueAt(Object value, int row, int col) {
if (DEBUG) {
System.out.println("Setting value at " + row + "," + col
+ " to " + value
+ " (an instance of "
+ value.getClass() + ")");
}
data[row][col] = value;
fireTableCellUpdated(row, col);
int ch;
int dab;
try {
if (col == 0) {
ch = Integer.valueOf(String.valueOf(data[row][1]));
dab = Integer.valueOf(String.valueOf(data[row][2]))-1;
plot.dab[ch].get(dab).visible = (boolean) value;
}
if (col == 3) {
ch = Integer.valueOf(String.valueOf(data[row][1]));
dab = Integer.valueOf(String.valueOf(data[row][2]))-1;
plot.dab[ch].get(dab).desc = String.valueOf(value);
}
plot.repaintCall();
} catch (NumberFormatException e) {e.printStackTrace();}
// System.out.println(ch + " " + dab);
if (DEBUG) {
System.out.println("New value of data:");
printDebugData();
}
}