can't listen to TextArea of Spinner



I want to know when the text field of a JSpinner is modified so that I
can turn on a radio button.
So I created the following class:

class ButtonSettingSpinnerNumberModel extends SpinnerNumberModel
implements DocumentListener {
AbstractButton button;

ButtonSettingSpinnerNumberModel(JSpinner spinner, AbstractButton
jButton,
int value, int minimum, int maximum, int stepSize) {
super(value, minimum, maximum, stepSize);
button = jButton;
JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor)
spinner.getEditor();
editor.getTextField().getDocument().addDocumentListener(this);
spinner.setModel(this);
}

public void changedUpdate(DocumentEvent e) {
button.setSelected(true);
}

public void removeUpdate(DocumentEvent e) {
button.setSelected(true);
}

public void insertUpdate(DocumentEvent e) {
button.setSelected(true);
}
}

Now I create an instance of the this class passing as parameters my
JSpinner and JRadioButton.

Now when the text field of the spinner is modified one of the three
update methods
(required for the DocumentListener Interface)
should be called because my instance is listening to the text field of
the spinner.
However my button is never selected and with the debugger I determined
that
the neither update method is invoked.

I do the same thing with A JTextField object and a different
JRadioButton and everything
works fine.

Any suggestions as to why this doesn't work?

Final note: I would like to be able to update my JRadioButtons when
the user clicks the
cursor into the JTextField (my proper JTextField or the one in the
JSpinner) rather than wait for
the text to be modified.
How can this be done?

Thanks to anyone who can help and I hope the problem/solutions are of
interest to others.

Ralph Boland
.


Quantcast