Forums Register Login

problems with custom JSpinner UI

+Pie Number of slices to send: Send
I trying to add a special JSpinner to my dialog that a) has the arrows to the right and left of the editor and b) updates the range and increment based on another GUI element.

For (a) I was trying to use the code provided by Darryl Burke

left right spinner

For (b) I was planning to update model.

Here is what I have so far-



This is Darryl's code.



As shown above, I get a GUI with a left-right spinner that works perfectly until I try to change the model,



If I comment out " spinner.setUI( new LeftRightSpinnerUI() );" I lose my left-right spinner, but can change the range and increment without problems.

I've been trying to sort out what I need to get both actions working, but I am somewhat confused about the relationship between the editor, UI and model. I see I can setEditor in JSpinner, but it is being created in LeftRightSpinnerUI and I'm not quite sure why it is recreated if I change the model. Could someone help me understand this better?

2
+Pie Number of slices to send: Send
 

Jon Swanson wrote:I trying to add a special JSpinner to my dialog that a) has the arrows to the right and left of the editor and b) updates the range and increment based on another GUI element.

For (a) I was trying to use the code provided by Darryl Burke

left right spinner

For (b) I was planning to update model.

...

As shown above, I get a GUI with a left-right spinner that works perfectly until I try to change the model,

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: cannot add to layout: unknown constraint: Editor


As said in the earlier thread, the suggested solution required (much) more testing. But it's easy to see where the error comes from; the layout manager used by BasicSpinnerUI (in private static class Handler) expects a constraint of "Editor" while the BorderLayout I substituted doesn't recognize "Editor" as a valid constraint. A quick an easy fix is to use an extended BorderLayout that translates "Editor" to CENTER. To do that, change the setLayout(...) call in installUI(...) toPlease tell us whether that solves your problem.
+Pie Number of slices to send: Send
Darryl,

Thank you very much (times 2, since the original post was also really helpful).

I made the change and my example works. I have a left-right spinner and can change the range and increment.
We don't have time for this. We've gotta save the moon! Or check this out:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3185 times.
Similar Threads
1 SpinnerDateModel with 3 spinners?
JSpinner arrow listener
JSpinner decimal input
Making JSpinner act like JSlider
Graphics Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:29:49.