I've noticed an annoyance with using JSpinner, particularly as a table editor.

It works fine if you just use the up/down buttons to change the valiue.

It also seems to work fine if you manually type in a number.  However, once you
move out of the field, the edited value goes away and is replaced by the
previous value.

This is apparently because of the disconnect between the
JSpinner.editor.textField and the JSpinner.model.

When you use the up/down buttons, each time the value changes, the method
"JSpinner.commitEdit()" is called, to "commit" the value from the textfield
into the spinner model.

When you edit the value manually, however, there is no such automatic moving of
the textfield value into the model.

Despite this, I could probably work around this if the JSpinner wasn't a table
editor.  Normally, I could just add a FocusListener to the component, and call
"JSpinner.commitEdit()" on "focusLost()".  Unfortunately, the way table editors
work, they never actually get the focus, and so don't lose it.

I tried setting up a DocumentListener on the textfield, to call "commitEdit()"
on any changes, but I found that causes an IllegalStateException, because the
call to "commitEdit()" actually modifies the textfield.  I suppose I could wrap
the call to "commitEdit()" in "invokeLater()", if that was really the way to do
this.

First of all, am I doing something wrong that is making this harder than it
should be?

Is there a way to properly resolve this?

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
[EMAIL PROTECTED]

_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to