我的JTable有一个密码字段编辑器.我想在用户单击编辑另一个字段时,如果文本长度小于8位,则显示错误消息.我尝试过焦点听众.但它不起作用.请帮帮我,因为我刚刚开始使用
java swing.
class PasswordEditor extends DefaultCellEditor
{
TextBox m_passWord = new TextBox();
public PasswordEditor() {
super(new TextBox());
}
@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.addInputMethodListener(new InputMethodListener() {
@Override
public void inputMethodTextChanged(InputMethodEvent event)
{
// TODO Auto-generated method stub
}
@Override
public void caretPositionChanged(InputMethodEvent event)
{
// TODO Auto-generated method stub
}
})
this.m_passWord.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e)
{
if (!e.isTemporary()) {
String content = PasswordEditor.this.m_passWord.getText();
System.out.println((content));
}
}
@Override
public void focusGained(FocusEvent e)
{
//TODO init
}
});
this.m_passWord.setEditable(true);
this.m_passWord.setText(fieldValue.toString());
return this.m_passWord;
}
}