Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6321570

JSpinner arrow buttons irresponsive for a date model

XMLWordPrintable

      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b44)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b44, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux localhost.localdomain 2.6.10-1.766_FC3 #1 Wed Feb 9 23:06:42 EST 2005 i686 i686 i386 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      On the JSpinner whose model is a SpinnerDateModel, two arrow buttons are irresponsive for user mouse clicks and date display doesn't spin. When user selects the step field of the spinner date display, e.g. minute field, with mouse and caret, it's suddenly got activated and normal spinning begins.

      This bug exists on J2SE 1.4.1, 1.4.2, 1.5.0 and 1.6.0, but NOT on 1.4.0.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Instantiate a JSpinner with SpinnerDateModel which uses four-argument constructor with non-null
      argument. Run the spinner and click the arrow buttons on it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
          When the user clicks the arrow buttons on the spinner, date display spins.
        ACTUAL -
          Buttons are irresponsive and spinner never spins.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.util.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class DateSpinnerWoe{
        JSpinner dateSpinner;
        SpinnerDateModel dateModel;
        Date s, e, v;
        int step, hour, minute;

        public DateSpinnerWoe(){
          hour = 6;
          minute = 45;
          step = Calendar.MINUTE;

          s = createDsParameter(hour, minute);
          e = createDsParameter(hour + 24, minute);
          v = createDsParameter(hour, minute + 5);

          dateModel = new SpinnerDateModel(v, s, e, step);
          dateSpinner = new JSpinner(dateModel);
          dateSpinner.setEditor
           (new JSpinner.DateEditor(dateSpinner, "yyyy MM dd HH:mm"));

          dateSpinner.addChangeListener(new ChangeListener(){
            public void stateChanged(ChangeEvent e){
              JSpinner spi = (JSpinner)e.getSource();
              try{
                spi.commitEdit();
              }
              catch (Exception ex){
                ex.printStackTrace();
              }
              System.out.println(spi.getValue());
            }
          });
        }

        private Date createDsParameter(int hr, int min){
          GregorianCalendar gc = new GregorianCalendar();
          gc.set(Calendar.HOUR_OF_DAY, hr);
          gc.set(Calendar.MINUTE, min);
          gc.set(Calendar.SECOND, 0);
          return gc.getTime();
        }

        public static void main(String[] args){
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          Container con = frame.getContentPane();
          DateSpinnerWoe ds = new DateSpinnerWoe();
          frame.add(ds.dateSpinner);
          frame.pack();
          frame.setVisible(true);
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None.

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: