大家好,想在 Jtextfield focusLost 检测填写是否正确,可在提示了出错信息后, 本来想返回这个 jtextfield, 不知道为何这个focuslost却被叫了很多次。 private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:evt.getSource();
JTextField roomTag=(JTextField) evt.getSource();
String text = roomTag.getText();
if (text.length() >= 3) {
try {
Integer.parseInt(text); } catch(NumberFormatException nfe) {
Toolkit.getDefaultToolkit().beep();
SwingUtilities.invokeLater(new FocusGrabber(this.jTextField1));
JOptionPane.showMessageDialog(null, "It must be a numeric value"); //roomTag.requestFocus();
//jTextField1.requestFocus();
//return;
}
} else {
JOptionPane.showMessageDialog(null, "It must be 3 chars at least");
//roomTag.requestFocus();
//jTextField1.requestFocus();
//return;
} }
// TODO add your handling code here:evt.getSource();
JTextField roomTag=(JTextField) evt.getSource();
String text = roomTag.getText();
if (text.length() >= 3) {
try {
Integer.parseInt(text); } catch(NumberFormatException nfe) {
Toolkit.getDefaultToolkit().beep();
SwingUtilities.invokeLater(new FocusGrabber(this.jTextField1));
JOptionPane.showMessageDialog(null, "It must be a numeric value"); //roomTag.requestFocus();
//jTextField1.requestFocus();
//return;
}
} else {
JOptionPane.showMessageDialog(null, "It must be 3 chars at least");
//roomTag.requestFocus();
//jTextField1.requestFocus();
//return;
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货