我有一個用於我的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;
}
}
我該如何改進? – Nikhil
你可以試試這個... ** String content = this.m_passWord.getText(); ** –
thenafter whats TextBox ??? – mKorbel