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

JScrollBar's setMaximum() inadvertently zero out its VisibleAmount(extent) value

XMLWordPrintable

    • beta
    • generic
    • solaris_2.6

      The JScrollBar's setMaximum() when use can cause the VisibleAmount(extent value)
      to be zeroed out. The following program will demonstrate the problem. Please
      also follow the given steps of instruction:

      1. Move the scrollbar's knob to its max value which is 90.
      2. Reset the scrollbar's max by enter 80 into the textfield and hit return.
      3. Notice that the "extend" goes to zero and the "value" goes to 80.

      Roger Pham 12/8/99
      ================================================================================

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


      public class JSB extends JFrame {
          public static void main(String argv[]) {
      JSB js = new JSB();
      js.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent we) {
                      System.exit(0);
                  }
              });
      js.pack();
      js.validate();
      js.setVisible(true);
      js.setSize(400, 200);
          }

          JScrollBar sb = new JScrollBar(JScrollBar.HORIZONTAL,50,10,0,100);;
          JTextField max = new JTextField("100", 4);
          JTextField min = new JTextField("0", 4);
          JTextField ext = new JTextField("10", 4);
          JTextField val = new JTextField("50", 4);

          JSB () {
      Container C = getContentPane();
      C.setLayout(new BorderLayout());

      C.add(BorderLayout.NORTH, sb);
      JPanel center = new JPanel(new GridLayout(5,0));
      C.add(BorderLayout.CENTER, center);

      JPanel p = new JPanel();
      p.add(new JLabel("Use the TextField to update values or move ScrollBar"));
      center.add(p);

      p = new JPanel();
      p.add(new JLabel("Maximum"));
      p.add(max);
      center.add(p);

      p = new JPanel();
      p.add(new JLabel("Minimum"));
      p.add(min);
      center.add(p);

      p = new JPanel();
      p.add(new JLabel("Extend"));
      p.add(ext);
      center.add(p);

      p = new JPanel();
      p.add(new JLabel("Value"));
      p.add(val);
      center.add(p);

      C.validate();

      sb.addAdjustmentListener(new AdjustmentListener() {
      public void adjustmentValueChanged(AdjustmentEvent e) {
      min.setText(new Integer(sb.getMinimum()).toString());
      max.setText(new Integer(sb.getMaximum()).toString());
      val.setText(new Integer(sb.getValue()).toString());
      ext.setText(new Integer(sb.getVisibleAmount()).toString());
      }
      });

      min.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      sb.setMinimum(Integer.valueOf(min.getText()).intValue());
                  }
              });

      max.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      sb.setMaximum(Integer.valueOf(max.getText()).intValue());
                  }
              });

      val.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      sb.setValue(Integer.valueOf(val.getText()).intValue());
                  }
              });

      ext.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      sb.setVisibleAmount(Integer.valueOf(ext.getText()).intValue());
                  }
              });

          }
      }

            peterz Peter Zhelezniakov
            rphamsunw Roger Pham (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: