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

JSlider(min,max) ctor: set initial value to midpoint between min and max

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.2.2, 1.4.0
    • client-libs
    • beta
    • generic
    • generic



      Name: krC82822 Date: 02/05/2001


      previous synopsis:
         "JSlider(min,max) ctor -> invalid range properties in DefaultBoundedRangeModel"

      5 Feb 2001, eval1127@eng -- as noted in the 1.3 docs, the (default) initial
      value is set to 50, independent of the min/max values specified. Thus,
      the initial value could end up outside the specified range (min->max),
      as in this case, where min=10, max=20.

      Thus, we should consider setting the initial value to the midpoint between
      mid and max. This is an ease-of-use issue. (It should be possible to
      use this "simpler" constructor with ranges which do not include the
      value 50. Otherwise, there's not much convenience associated
      with this two-arg constructor.)

      ---------------
      java version "1.2.2"
      Classic VM (build JDK-1.2.2_005, native threads, symcjit)

      through

      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b50)
      Java HotSpot(TM) Client VM (build 1.4beta-B50, mixed mode)


      /*
      If you use this code, an exception was throws. The output is:
      java.lang.IllegalArgumentException: invalid range properties
      at javax.swing.DefaultBoundedRangeModel.<init>
      (DefaultBoundedRangeModel.java:91)
      at javax.swing.JSlider.<init>(JSlider.java:198)
      at javax.swing.JSlider.<init>(JSlider.java:171)
      at untitled1.Frame1.<init>(Frame1.java:18)
      at untitled1.Frame1.main(Frame1.java:30)


      If you set "max = 70", you have no problem.
      The 2 arguments JSlider costructor is wrong. Look that code
      */

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

      public class Frame1 extends JFrame {
        int min = 10;
        int max = 20;
        JSlider jSlider1 = new JSlider(min,max);

        public Frame1() {
          try {
            jbInit();
          }
          catch(Exception e) {
            e.printStackTrace();
          }
        }

        public static void main(String[] args) {
          Frame1 frame11 = new Frame1();
          frame11.setSize(200,200);
          frame11.setVisible(true);
        }

        private void jbInit() throws Exception {
          this.addWindowListener(new java.awt.event.WindowAdapter() {

            public void windowClosing(WindowEvent e) {
              this_windowClosing(e);
            }
          });
          this.getContentPane().add(jSlider1, BorderLayout.CENTER);
        }

        void this_windowClosing(WindowEvent e) {
          System.exit(0);
        }
      }

      ----------------------

      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b50)
      Java HotSpot(TM) Client VM (build 1.4beta-B50, mixed mode)

      Exception in thread "main" java.lang.IllegalArgumentException: invalid range properties
              at javax.swing.DefaultBoundedRangeModel.<init>(DefaultBoundedRangeModel.java:86)
              at javax.swing.JSlider.<init>(JSlider.java:198)
              at javax.swing.JSlider.<init>(JSlider.java:171)
              at Frame116364.<init>(Frame116364.java:28)
              at Frame116364.main(Frame116364.java:40)


      (Review ID: 116364)
      ======================================================================

            joutwatesunw Joshua Outwater (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: