yes, there's an area of Java I'm almost a complete novice in (so far, I'm going full steam ahead :cheesy: ).
I've the following code to filter out non-numeric input from a JTextField (which is meant to contain a timeout interval in minutes, that's why).
private void dumpNonNumericInput(KeyEvent e) {
char input = e.getKeyChar();
String oldText = ((JTextField)e.getSource()).getText();
if (input != KeyEvent.VK_BACK_SPACE && input != KeyEvent.VK_DELETE &&
(input < '0' || input > '9')) {
JOptionPane.showMessageDialog(this, "Numeric input required",
"Input error",
JOptionPane.ERROR_MESSAGE);
e.consume();
((JTextField)e.getSource()).setText(oldText);
}
}
This method works like a charm, that's not the problem.
The problem is that is I remove the error message popup (just the showMessageDialog command) the method no longer removes the faulty input either.
I THINK it's something to do with Swing thread timing, but I'm not sure.
Neither do I know how to cure this, which is more important at the moment as I'd rather not have that popup appear every time someone makes a typo.
I could probably subclass JTextField but that may be more trouble than it's worth.