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

JSlider arrow key repetitions should make getValueIsAdjusting() return true

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.4.0, 1.4.2
    • client-libs
    • generic, x86
    • generic, windows_2000



      Name: js151677 Date: 07/02/2004


      A DESCRIPTION OF THE REQUEST :
      The API does not specify when for a JSlider the value is considered to be adjusting. The current implementation only considers the value to be adjusting when mouse drag events are occurring. My request is that JSlider also consider the value to be adjusting when a key that changes the value (arrow keys, Page Up, Page Down) is pressed down.

      JUSTIFICATION :
      Although the JSlider API specifically states that getValueISAdjusting() returns true when a knob drag is underway, the documentation for the underlying BoundedRangeModel states that getValueIsAdjusting() "returns true if the current changes to the value property are part of a series of changes." When a user holds down an arrow key to adjust a JSlider, we expect the related changes to the value property of the underlying BoundedRangeModel to be "part of a series of changes." It seems to me that the suggested behavior would be more consistent than the current implementation.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When a value change occurs on a JSlider due to a key press, as long as the key remains pressed getValueIsAdjusting() should return true. Additionally, when an associated key is released or when focus is lost, a ChangeEvent should be fired so that listeners can detect that the value is no longer adjusting. (This is consistent with the way a mouse drag works except for that focus cannot be lost while a mouse drag is underway.)
      ACTUAL -
      For any ChangeEvent fired by a JSlider value due to a key press, getValueIsAdjusting() returns false for registered listeners.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import javax.swing.JFrame;
      import javax.swing.JSlider;
      import javax.swing.event.ChangeEvent;
      import javax.swing.event.ChangeListener;

      public class SliderRFE extends JFrame {

        private JSlider slider;

        public SliderRFE() {
          slider = new JSlider();
          slider.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
              System.out.println("Value is adjusting: "
                  + slider.getValueIsAdjusting());
            }
          });
          getContentPane().add(slider);
        }

        public static void main(String[] args) {
          JFrame frame = new SliderRFE();
          frame.setSize(new Dimension(200, 100));
          frame.setVisible(true);
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Could register a KeyListener and a FocusListener on the JSlider which could detect whether one of the keys that affects the value was being held down -- pressed and not released while maintaining focus Hence it is possible to implement a pair of listeners which determine whether the value is adjusting due to key presses. Proposed implementation would also have to respond to key release and focus lost events as if they were change events.
      (Incident Review ID: 282206)
      ======================================================================

            Unassigned Unassigned
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: