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

JSpinner buttons don't conform to most platform conventions

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 5.0
    • 1.4.1
    • client-libs
    • tiger
    • x86
    • windows_2000

    Description



      Name: jk109818 Date: 12/04/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      ADDITIONAL OPERATING SYSTEMS :
      Probably all OSs



      A DESCRIPTION OF THE PROBLEM :
      The JSpinner fails to follow standard conventions for dragging the mouse pointer outside of the controls.
      According to both Windows and Macintosh conventions, the value should stop changing as soon as the
      pointer leaves the JButton's rectangle, and should resume changing when the pointer re-enters the
      JButton. The same convention applies to most controls. A JButton, for example will appear pressed when
      the mouse is pressed. Then it will appear unpressed when the mouse either sends a mouseUp, or the
      pointer is dragged out of the JButton Rectangle. If it is dragged back in before the button is released, the
      button will appear pressed again. The action is fired only if the button is released when the pointer is
      inside the button. A JSpinner button should behave the same way, with one addition: The spinner value
      should stop changing when the user drags the mouse out of the button's rectangle. The JButton correctly
      follows this convention, but the JSpinner doesn't. Swing components should follow the standard platfrom
      conventions.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Launch the program provided below
      2. Click into either JSpinner arrow.
      3. Without releasing the mouse button, drag the mouse outside of the arrow.

      At this point, the JSpinner value should stop changing, but it keeps going.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The spinner should change its value only when three conditions are met
      1) The mouseDown event happened inside a JSpinner button.
      2) The corresponding mouseUp event hasn't happened yet.
      3) The pointer is inside the mouse rectangle.

      The third condition is never used.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class SpinDemo1 {
          private final static int iMax = 500;
          public static void main(String args[]) {

              // create a JFrame
              JFrame frame = new JFrame("SpinDemo1");
              frame.setDefaultCloseOperation(
                  JFrame.EXIT_ON_CLOSE);

              // create a JSpinner with a range of
              // values 1-iMax (15) and starting value 1
              // and increment 1

              final SpinnerModel sm =
                  new SpinnerNumberModel(new Integer(iMax/2),
                  new Integer(1), new Integer(iMax),
                      new Integer(1));
              JSpinner jsp = new JSpinner(sm);

              // add a change listener

              jsp.addChangeListener(
                  new ChangeListener() {
                      public void stateChanged(
                          ChangeEvent e) {
                              System.out.println(
                                  "changed: " +
                                  sm.getValue());
                      }
                  });

              // create a JComboBox

              Object list[] = new Object[iMax];
              for (int ii=0; ii<iMax; ++ii)
                  list[ii] = new Integer(ii+1);
              JComboBox jcb = new JComboBox(list);
              jcb.setEditable(true);

              // create a JPanel

              JPanel panel = new JPanel();
              panel.setPreferredSize(
                  new Dimension(300, 300));
              panel.add(jsp);
              panel.add(jcb);
              frame.getContentPane().add(panel);

              // display the frame

              frame.pack();
              frame.setVisible(true);
          }
      }

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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: