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

JScrollPane's always-visible scrollbars not updated when viewport is replaced

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.3.1
    • client-libs
    • tiger
    • generic
    • generic



      Name: jk109818 Date: 12/04/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-root-
      010902-18:51)
      Java HotSpot(TM) Client VM (build 1.3.1, mixed mode)


      If you have a JScrollPane with a scrollbar set to be always visible, and the
      contents are large enough that the scrollbar has the thumb showing, if
      you set the viewport to null (causing it to create a new JViewport with no
      view), the scrollbar stays set to that value and it can be scrolled. The
      scrollbar should become inactive, with no visible thumb.

      When the scrollbars are as_needed, they disappear, as they should.

      revalidate doesn't force it to update itself, but it will if you resize the
      scrollpane or the viewport.

      Steps to reproduce:

      Run the example code below. Click the button to remove the viewport.
      The scrollbar is still active. Now resize the window, and the scrollbar will
      become inactive.


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

      public class Test {
      public static void main(String[] args) {
      new Test();
          }

      public Test() {
      JFrame fr = new JFrame("Test");
      fr.getContentPane().add(testComponent());
      fr.setSize(new Dimension(320, 200));
      fr.show();
      }
      JScrollPane scrollpane;
      JComponent testComponent() {
      JPanel p = new JPanel();

      String[] items = new String[30];
      for (int i = 0; i < 30; i++)
      items[i] = new String("" + i);

      JList list = new JList(items);
      scrollpane = new JScrollPane(list
      ,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
      JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      p.add(scrollpane);

              p.setLayout(new GridLayout(0,1));
      JButton b = new JButton("Press me");
      b.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      scrollpane.setViewportView(null);
      scrollpane.revalidate();
      // workaround
      // scrollpane.getViewport().setBounds(0,0,0,0);
      }
      });
      p.add(b);


      return p;
      }
      }
      (Review ID: 136111)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: