Solved

JSpinner not spinning

Posted on 2003-12-02
6
373 Views
Last Modified: 2007-12-19
I have the following code that creates a JSpinner.  However, the JSpinner doesn't spin as expected (by DATE) -- it doesn't spin at all.  If you see anything wrong, please suggest a fix.

      GregorianCalendar calendar = new GregorianCalendar ();
      calendar.add (Calendar.DATE, -1); // Todays date minus one day (data is always one day behind);
      Date initDate = calendar.getTime ();
      calendar.add (Calendar.DATE, -14);
      Date earliestDate = calendar.getTime ();
      Date latestDate = initDate;

      SpinnerDateModel dateModel
        = new SpinnerDateModel (initDate,
                                earliestDate,
                                latestDate,
                                Calendar.DATE);
     
      dateFrom = new JSpinner (dateModel);
      dateFrom.setEditor (new JSpinner.DateEditor(dateFrom, "MM/dd/yy"));
 
      dateTo = new JSpinner (dateModel);
      dateTo.setEditor (new JSpinner.DateEditor (dateTo, "MM/dd/yy"));
0
Comment
Question by:sapientconceptions
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
yongsing earned 25 total points
ID: 9864417
It seems that Calendar.DATE is not a legal value for the last parameter of the SpinnerDateModel's contructor. Try Calendar.DAY_OF_WEEK instead.
0
 
LVL 3

Expert Comment

by:monkesdb
ID: 9864522
too true

the calanderField element of the constructor is the amount by which the date increments or decrements as you spin.

calendarField can be one of
Calendar.ERA
Calendar.YEAR
Calendar.MONTH
Calendar.WEEK_OF_YEAR
Calendar.WEEK_OF_MONTH
Calendar.DAY_OF_MONTH
Calendar.DAY_OF_YEAR
Calendar.DAY_OF_WEEK
Calendar.DAY_OF_WEEK_IN_MONTH
Calendar.AM_PM
Calendar.HOUR
Calendar.HOUR_OF_DAY
Calendar.MINUTE
Calendar.SECOND
Calendar.MILLISECOND
0
 

Author Comment

by:sapientconceptions
ID: 9864868
Thanks for the suggestion, but after changing that value, the spinner still doesn't spin.  Any other suggestions?  I'm clueless right now!
0
 
LVL 3

Assisted Solution

by:monkesdb
monkesdb earned 25 total points
ID: 9878732
here's a thought

just to test it...

      Integer[] tst = {new Integer(1), new Integer(2), new Integer(3)};
      SpinnerListModel model = new SpinnerListModel(tst);

try this, although by all rights your code should work.

      GregorianCalendar calendar = new GregorianCalendar ();

      Date latestDate = calendar.getTime ();
      calendar.add (Calendar.DATE, -1); // Todays date minus one day (data is always one day behind);
      Date initDate = calendar.getTime ();
      calendar.add (Calendar.DATE, -14);
      Date earliestDate = calendar.getTime ();

      SpinnerDateModel dateModel
        = new SpinnerDateModel (initDate,
                                earliestDate,
                                latestDate,
                                Calendar.DATE);
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now