I have a JTable that has a custom editor. I am validating a cell entry and then attempting to clear that cell entry and keep the user in that same cell if it is an invalid entry. I have accomplished the clearing of the invalid data in the cell, but am unable to keep the focus on the current cell after the data has been cleared. The portion of the custome cell editor is below, thanks.
public Object getCellEditorValue() {
// Set heirarchy row values.
int currRow = detailTable.getEditingRow();
int currColumn = detailTable.getEditingColumn();
String subTable = (String)detailTable.getValueAt(currRow, 0);
// Don't validate the criteria if it is null.
if (((JTextField)component).getText().length() > 0) {
// Validate the criteria.
if (!datasourceConnection.validSqlStatement(subTable, ((JTextField)component).getText())) {
// Invalid criteria, clear the criteria field.
JOptionPane.showMessageDialog(null, "This is an invalid criteria entry.", "Criteria Status", JOptionPane.ERROR_MESSAGE);
((JTextField)component).setText("");
detailTable.setColumnSelectionAllowed(true);
detailTable.setRowSelectionAllowed(true);
detailTable.changeSelection(currRow, currColumn, false, false);
}
}
// Return the field value.
return ((JTextField)component).getText();
}