• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems with custom JSpinner UI

 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5132
11
Java Netbeans IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic