textBoxName.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
onChange();
}
@Override
public void removeUpdate(DocumentEvent e) {
onChange();
}
@Override
public void changedUpdate(DocumentEvent e) {
onChange();
}
});
But I would not just parse anything the user (maybe on accident) touches on his keyboard into an Integer
. You should catch any Exception
s thrown and make sure the JTextField
is not empty.