B
Boris Pelakh
I have a table with a text column. I would like to ensure that the
values in that column remain unique when edited. I have created the
following class
class NameTextField extends JFormattedTextField {
Set currentNames = null;
public void setCurrentNames(Set currentNames) {
this.currentNames = currentNames;
}
public boolean isEditValid() {
String val = getFormatter().toString();
System.out.println("isEditValid called with '"+val+"'");
if (val == null || val.length() == 0 ||
currentNames.contains(val)) {
return false;
}
else {
return super.isEditValid();
}
}
}
I then set the CellEditor for the column with
TableColumn nameColumn =
getColumnModel().getColumn(AttributeTableModel.NAME_COL);
text = new NameTextField();
nameColumn.setCellEditor(new DefaultCellEditor(text));
I expect isEditValid() to be called each time I press 'Enter' after
editing the field. I would also expect that if I returned false, the
field would retain focus and force the user to correct the problem.
What I get is the method is not getting called at all. What am I doing
wrong? Do I need to define a Formatter? FormatterFactory?
values in that column remain unique when edited. I have created the
following class
class NameTextField extends JFormattedTextField {
Set currentNames = null;
public void setCurrentNames(Set currentNames) {
this.currentNames = currentNames;
}
public boolean isEditValid() {
String val = getFormatter().toString();
System.out.println("isEditValid called with '"+val+"'");
if (val == null || val.length() == 0 ||
currentNames.contains(val)) {
return false;
}
else {
return super.isEditValid();
}
}
}
I then set the CellEditor for the column with
TableColumn nameColumn =
getColumnModel().getColumn(AttributeTableModel.NAME_COL);
text = new NameTextField();
nameColumn.setCellEditor(new DefaultCellEditor(text));
I expect isEditValid() to be called each time I press 'Enter' after
editing the field. I would also expect that if I returned false, the
field would retain focus and force the user to correct the problem.
What I get is the method is not getting called at all. What am I doing
wrong? Do I need to define a Formatter? FormatterFactory?