怎样实现不允许对话框的EditText的输入内容为空

2024-12-02 17:35:02
推荐回答(1个)
回答1:

TextField tf = new TextField ();
//对该文本框进行监听

tf.addFocusListener (new FocusListener(){
// 失去焦点的时候
@Override
public void focusLost(FocusEvent e) {
if(tf.getText.length ==0 || tf.getText.equals("")){
JOptionPane.showMessageDialog(tf, "请输入文本", "提示",
JOptionPane.YES_OPTION);
}

}
@Override

public void focusGained(FocusEvent e) {

}
});