怎样实现不允许对话框的EditText的输入内容为空
展开全部
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) {
}
});
//对该文本框进行监听
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) {
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询