I have a Password field editor for my JTable. I want to display an error message if the text length is less than 8 bit when the user clicks to edit another field. I have tri
Override the stopCellEditing() and u can try the below code to get the focus for the error cell.
class PasswordEditor extends DefaultCellEditor
{
private TextBox m_passWord = new TextBox();
public PasswordEditor() {
super(new TextBox());
}
@Override
public boolean stopCellEditing()
{
if(getCellEditorValue().toString().length() < 8)
{
// Text box will get the focus and will shown in Red line as border for that cell.
TextBox aTextBox = (TextBox)getComponent();
aTextBox.setBorder(new LineBorder(Color.red));
aTextBox.selectAll();
aTextBox.requestFocusInWindow();
JOptionPane.showMessageDialog(UsmUserView.this.m_Parent, "Password Must Be 8 Bytes Long !! Please Check");
return false;
}
return super.stopCellEditing();
}
@Override
public Object getCellEditorValue() {
return this.m_passWord.getText();
}
@Override
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
Object fieldValue = value;
if(null == fieldValue)
fieldValue = Constants.EMPTY_STRING;
this.m_passWord.setEditable(true);
this.m_passWord.setText(fieldValue.toString());
return this.m_passWord;
}
}