Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSpinner - How to initialize to the top of list

 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am loading a JSpinner with a ascending sorted list of names; need to set the current row to show at startup the first, not the last row loaded. Have searched and do not see any method to do this in either the model or JSpinner....
thanks in advance!
 
Brian Cole
Author
Ranch Hand
Posts: 906
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure exactly what you are asking.

If you want to force your JSpinner to select a specific value you can call yourSpinner.setValue().

If you're trying to muck with the order of your SpinnerListModel somehow (which, despite "top of list" in the subject line, seems odd if it is sorted) then please explain what you're trying to do in more detail.
 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK - I have a list of names, say - Andy, Bill, Christina. These names are loaded into the array used to initialize JSpinner in this order - [0] Andy, [1] Bill, [3} Christina. When the JSpinner appears, "Christina" shows up, requiring the user to go up to find the rest of the names. Intuitively, one would expect the top name, Andy, to be shown and click on the down arrow of the spinner to get the rest of the names. I would have thought there was a "setCurrent" or some such method to point to the top of the list....thanks for any ideas...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works OK like this (1.4.0_01)

 
Brian Cole
Author
Ranch Hand
Posts: 906
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[0] Andy, [1] Bill, [2] Christina

Originally posted by Douglas Kent:
I would have thought there was a "setCurrent" or some such method to point to the top of the list.


Well, again, I'm confused by "top of the list." I would say that Andy will always be the top of the list, even the current selected value of the spinner is Bill or Christina.

But that aside, let me say again that the setValue() method would seem to be the method you are looking for. Just call yourSpinner.setValue("Andy") or yourSpinner.setValue(yourValueArray[0]). Simple, right? Or am I missing something?
[ January 24, 2007: Message edited by: Brian Cole ]
 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian,
All I want to do is set the default selected row to the "top" item (Andy in this example) instead of the last (Christina) as it happens when I create the spinner.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic