Solved

JSpinner not spinning

Posted on 2003-12-02
6
397 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
[X]
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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