?
Solved

JSpinner not spinning

Posted on 2003-12-02
6
Medium Priority
?
413 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 100 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 100 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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