0
以下是代码块,我一直试图验证jFormatedTextFeild。当键入键(任何键)代码块似乎执行键入的第一个键。但对第二个键输入正常工作!请帮我:(按键输入的事件不适用于键入的第一个键。 java
private void jFormattedTextField_ByingPriceKeyTyped(KeyEvent evt) {
System.out.println("key typed action ");
String checking = jFormattedTextField_ByingPrice.getText();
Pattern ptrn = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
Matcher match = ptrn.matcher(checking);
if(match.find()){
txtPriceMessage.setVisible(true);
//text field which contains the message does not appears
//for first key typed only it appears when second key is typed.
} else {
txtPriceMessage.setVisible(false);
}
}
你需要发布更多的代码尤其是与的KeyListener位。 – anonymous
IIRC的关键领域实际上改变了文本之前输入的事件发生,这可以解释你看到的行为(你可以fi通过在活动期间简单地打印文本来发现此问题。) – Radiodef
以及解决方案@radiodef – dip