This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JSpinner - How to initialize to the top of list 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 "JSpinner - How to initialize to the top of list" Watch "JSpinner - How to initialize to the top of list" New topic
Author

JSpinner - How to initialize to the top of list

Douglas Kent
Ranch Hand

Joined: Oct 06, 2000
Posts: 171
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

Joined: Sep 20, 2005
Posts: 862
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.


bitguru blog
Douglas Kent
Ranch Hand

Joined: Oct 06, 2000
Posts: 171
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

Joined: Jun 09, 2003
Posts: 4632
works OK like this (1.4.0_01)

Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
[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

Joined: Oct 06, 2000
Posts: 171
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSpinner - How to initialize to the top of list
 
Similar Threads
What's the name of a GUI control with 2 arrows...
JSpinner
JWhat
ascii decimal conversion problem
Set range value for JTextField?