Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JSpinner not spinning

Posted on 2003-12-02
6
393 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

809 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