Even though I think you should rewrite the question I will try to answer.
I am quessing that you should be asking how to let a user know that he entered an invalid input into a textfield, as probably that is where the phone number is.
Why don't you then highlight either the background of the text field to red tf.setBackground(Color.RED) or its border tf.setBorder(BorderFactory.createLineBorder(Color.PINK, 5)) ?
This way you do not need to show the dialog, and user knows something is wrong in this field.
发布评论
评论(4)
在控制台上使用
System.out.println("Your MEssage");
?或者在某些 JFrame 上的JLabel
上?On the Console with
System.out.println("Your MEssage");
? Or on aJLabel
on some JFrame?怎么样:
What about:
尽管我认为你应该重写这个问题,但我会尽力回答。
我想知道您应该问如何让用户知道他在文本字段中输入了无效的输入,因为这可能就是电话号码所在的位置。
那么为什么不将文本字段的背景突出显示为红色
tf.setBackground(Color.RED)
或其边框tf.setBorder(BorderFactory.createLineBorder(Color.PINK, 5) ))
?这样您就不需要显示对话框,并且用户知道该字段中出现问题。
Even though I think you should rewrite the question I will try to answer.
I am quessing that you should be asking how to let a user know that he entered an invalid input into a textfield, as probably that is where the phone number is.
Why don't you then highlight either the background of the text field to red
tf.setBackground(Color.RED)
or its bordertf.setBorder(BorderFactory.createLineBorder(Color.PINK, 5))
?This way you do not need to show the dialog, and user knows something is wrong in this field.
InputVerifier
可能适合这种情况。InputVerifier
may be suitable in this context.