public void caretUpdate(CaretEvent e) {
        try {
            int testValue = Integer.valueOf(textField.getText()).intValue();

            if ((testValue >= min) && (testValue <= max)) {
                textField.setForeground(darkGreen);
                setValue(testValue, false, true);
            } else {
                textField.setForeground(Color.red);
            }
        } catch (Exception ex) {
            if (ex instanceof NumberFormatException) {
                textField.setForeground(Color.red);
            }

            // Ignore all other exceptions, e.g. illegal state exception
        }

        textField.repaint();
    }