1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public class MyInputVerifier extends InputVerifier{
public boolean verify(JComponent input){
try{
Integer.parseInt(((JTextField)input).getText());
}
catch(NumberFormatException e){
return false;
}
return true;
}
@Override
public boolean shouldYieldFocus(JComponent input) {
if (verify(input)) {
return true;
}
input.setInputVerifier(null); //-- Temporary remove verifier (bug in 1.4 only)
JOptionPane.showMessageDialog(null, "Le numéro de séquence de la ligne doit être " +
"renseigné et doit être un entier.", "Erreur", JOptionPane.ERROR_MESSAGE);
input.setInputVerifier(this); //-- Reinstall the input verifier (bug 1.4)
return false; //-- We don't want to yield focus
}
} |
Partager