Scenario is like this: user edits a cell, and presses TAB. Editing is stopped, and value is in the model. However, if postUpdateTestFailed()
returns true, I want to move selection back to the just edited cell so user can do some modification. Problem is, it does not work. It works for anything else but the selected cell in my case... :( Because user presses TAB, focused/selected cell is always the next one. Seems like my selection changing is ignored in this particular case. What am I doing wrong? :)
public void tableChanged(TableModelEvent tme) {
int row = tme.getFirstRow();
int col = tme.getColumn();
int type = tme.getType();
switch (type) {
case TableModelEvent.UPDATE:
currentRow = areenTable.convertRowIndexToView(row);
currentColumn = areenTable.convertColumnIndexToView(col);
if (postUpdateTestFailed()) {
// if the test fails, I want to move back to the edited cell
areenTable.changeSelection(currentRow, currentColumn, false, false);
}
break;
// the rest of switch
} // switch
} // tableChanged() method
Edit 1 : I was hoping that someone experienced the same problem before and solved it somehow...
Edit 2: I would normally do this in my own cell-editor implementation, and prevent commit if validation fails. Unfortunately, in this special case I have to call postUpdateTestFailed()
after the change is committed... And then position cursor to the previously edited cell. Weird thing is that I can move to any other cell, but the last edited one!! I consider this a bug.