Solved

JSpinner not spinning

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 69
Opening PDF on button click and fill new document 2 35
how to see all occupied ports on windows 10 laptop 15 61
servlet example 17 28
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

813 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

18 Experts available now in Live!

Get 1:1 Help Now