permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes problems with custom JSpinner UI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problems with custom JSpinner UI" Watch "problems with custom JSpinner UI" New topic
Author

problems with custom JSpinner UI

Jon Swanson
Ranch Hand

Joined: Oct 10, 2011
Posts: 193
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?

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Jon Swanson
Ranch Hand

Joined: Oct 10, 2011
Posts: 193
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems with custom JSpinner UI
 
Similar Threads
Making JSpinner act like JSlider
JSpinner decimal input
JSpinner arrow listener
How to change jspinner up/down arrows from right to left
1 SpinnerDateModel with 3 spinners?