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

SpinnerDateModel behavior not changed when calling setCalendarField

XMLWordPrintable

    • tiger
    • x86
    • windows_2000



      Name: jk109818 Date: 03/18/2003


      FULL PRODUCT VERSION :
      j2re1.4.1_01

      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)


      FULL OPERATING SYSTEM VERSION :
      Windows 2000, 5.00.2195, SP 1

      ADDITIONAL OPERATING SYSTEMS :
      Windows 98 (second edition, 4.10.2222 A)
      NT 4.0 SP6a


      A DESCRIPTION OF THE PROBLEM :
      JSpinner and JSpinnerDateModel
      model.setCalendarField(Calendar.YEAR);
      it is the same if you try MONTH or DAY_OF_MONTH ...
      does not affect the behaviour of the model (it is always the
      day field which is incremented or decremented)



      REGRESSION. Last worked in version 1.4

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------


      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.border.*;

      public class Gaga777 {


        static JSpinner spinner = null;
        static JCheckBox use = null;
        static JRadioButton year = null;
        static JRadioButton month = null;
        static JRadioButton day = null;
        static JButton getVal = null;

        public static void main(String[] args) {
          
          {
            JFrame frame = new JFrame("HOP");
            frame.getContentPane().setLayout(new BorderLayout());
            JPanel panel = new JPanel(
                new GridLayout(1,0));
            panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
            //
            JRadioButton rb = null;
            JCheckBox cb = null;
            cb = new JCheckBox("Valid from");
            use = cb;
            cb.setSelected(true);
            cb.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                      JCheckBox cb = (JCheckBox)e.getSource();
                      boolean v = cb.isSelected();
                      spinner.setEnabled(v);
                      ((JSpinner.DefaultEditor)
                       spinner.getEditor()).getTextField().setEditable(false);
                      year.setEnabled(v);
                      month.setEnabled(v);
                      day.setEnabled(v);
                      getVal.setEnabled(v);
                    }
                  });
            panel.add(cb);
            year = new JRadioButton("By year");
            year.setEnabled(true);
            rb = year;
            rb.setSelected(false);
            rb.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                      SpinnerDateModel model = (SpinnerDateModel)
                        spinner.getModel();
                      model.setCalendarField(
                          Calendar.YEAR
                          );
                    }
                  });
            panel.add(year);
            month = new JRadioButton("By month");
            month.setEnabled(true);
            rb = month;
            rb.setSelected(false);
            rb.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                      SpinnerDateModel model = (SpinnerDateModel)
                        spinner.getModel();
                      model.setCalendarField(
                          Calendar.MONTH
                          );
                    }
                  });
            panel.add(month);
            day = new JRadioButton("By day");
            day.setEnabled(true);
            rb = day;
            rb.setSelected(true);
            rb.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                      SpinnerDateModel model = (SpinnerDateModel)
                        spinner.getModel();
                      model.setCalendarField(
                          Calendar.DAY_OF_MONTH
                          );
                    }
                  });
            panel.add(day);
            ButtonGroup bg = new ButtonGroup();
            bg.add(year);
            bg.add(day);
            bg.add(month);
            //
            SpinnerDateModel model = new SpinnerDateModel(
                java.sql.Date.valueOf("2002-12-10"),
                java.sql.Date.valueOf("2002-12-10"),
                java.sql.Date.valueOf("2202-12-20"),
                Calendar.DAY_OF_MONTH);
            spinner = new JSpinner(model);
            System.out.println("spinner = " + spinner.getPreferredSize());
            Dimension dim = spinner.getPreferredSize();
            spinner.setPreferredSize(
                new Dimension((int)150, (int)dim.getHeight()));
            spinner.setEnabled(true);
            spinner.setEditor(
                new JSpinner.DateEditor(spinner, "dd.MM.yyyy: MMM, EEE"));
            ((JSpinner.DefaultEditor)
             spinner.getEditor()).getTextField().setEnabled(false);
            spinner.addChangeListener(
                new ChangeListener() {
                    public void stateChanged(ChangeEvent e) {
                      if (use.isSelected()) {
                        SpinnerModel model =
                          (SpinnerModel)spinner.getModel();
                        System.out.println("value = " + model.getValue());
                      }
                    }
                  });
            panel.add(spinner);
            //
            frame.getContentPane().add(panel, BorderLayout.NORTH);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
          }

        }
      }

      ---------- END SOURCE ----------
      (Review ID: 179202)
      ======================================================================

            apikalev Andrey Pikalev
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: