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

JScrollBar fails to render thumbs under Nimbus UI when viewport is too large

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • None
    • 8u60
    • client-libs

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux dev2 3.13.0-62-generic #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
      This is a fairly standard Linux Mint 17.1 machine.
      I have also seen this behaviour on a Windows XP SR3 machine in our office.

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Have tried under both compiz and Metacity window managers with same result.

      A DESCRIPTION OF THE PROBLEM :
      When using Nimbus as the UI, if the viewport of a JScrollPane is large enough that the calculated scale of either thumb in the scrollbars would be less than the actual minimum size of that thumb, then that thumb is not painted at all.

      In all (to my knowledge) previous releases the thumb continues to be plotted at its actual minimum size in this circumstance, or whatever size is available for it in the scrollbar, whichever is the smaller.

      The upshot of this is that when a JList/JTable in a JScrollPane grows too large, the thumb disappears, giving the user nothing to visibly drag.

      The scrollbar acts as though the thumb is still present (ie it can still be dragged). However it cannot be seen.

      Note that if the size of the contents of the JScrollPane reduces (eg enough elements are removed from the JList/JTable), then the thumb(s) will reappear. Similarly expanding the JScrollPane can make the thumb(s) reappear.

      REGRESSION. Last worked in version 8u51

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Sample code attached below.

      Just create a JScrollPane with a large component inside it. If the preferred size of the component is large enough, the thumb in the scroll bar will disappear.

      In the sample code, the component is a JList with the default visible row count of 8 items. In this case increasing the number of items in the JList to 32 or more is enough to reproduce the problem. So is reducing the height of the JFrame so that less than 5 items are completely visible in the JList.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The thumb(s) in the scrollbar(s) should shrink in size as the number of items in the JList increases or the size of the JScrollPane decreases until they have reached their minimum size. Then they should remain visible at their minimum size until there physically isn't enough room to fit them onto the scrollbar, at which point they should continue to shrink to fit the available space.
      ACTUAL -
      The thumb(s) in the scrollbar(s) shrink in size as the number of items in the JList increases or the size of the JScrollPane decreases. Once they have shrunk to minimum size they disappear completely.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.AbstractListModel;
      import javax.swing.JCheckBox;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JList;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JSpinner;
      import javax.swing.SpinnerNumberModel;
      import javax.swing.SwingUtilities;
      import javax.swing.UIManager;
      import javax.swing.UIManager.LookAndFeelInfo;
      import javax.swing.event.ChangeEvent;
      import javax.swing.event.ChangeListener;

      public class TestThumb {

      public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
      new TestThumb().startUi();
      }
      });
      }

      private class MyListModel extends AbstractListModel<String> {

      private static final long serialVersionUID = -3791947364926818808L;

      private int size = 10;

      public void setSize(int newSize) {
      if (size != newSize) {
      int oldSize = size;
      size = newSize;
      fireContentsChanged(this, oldSize, newSize);
      }
      }

      @Override
      public int getSize() {
      return size;
      }

      @Override
      public String getElementAt(int index) {
      return "List Element #" + index;
      }

      }

      public void startUi() {
      try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
      if ("Nimbus".equals(info.getName())) {
      UIManager.setLookAndFeel(info.getClassName());
      break;
      }
      }
      } catch (Exception e) {
      System.err.println("Couldn't set UI to Nimbus: " + e);
      return;
      }

      JFrame frame = new JFrame("Test Scrollbar Thumb");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      JPanel content = new JPanel(new BorderLayout());

      JPanel hdrPanel = new JPanel();
      hdrPanel.add(new JLabel("JRE Version " + System.getProperty("java.version")));
      content.add(hdrPanel, BorderLayout.NORTH);

      final MyListModel listModel = new MyListModel();

      final JList<String> list = new JList<String>(listModel);

      JScrollPane scrollPane = new JScrollPane(list);
      content.add(scrollPane, BorderLayout.CENTER);

      final JSpinner spinner = new JSpinner(new SpinnerNumberModel(10, 0, 10000, 10));
      spinner.addChangeListener(new ChangeListener() {

      @Override
      public void stateChanged(ChangeEvent e) {
      Object val = spinner.getValue();
      if (val instanceof Number) {
      Number num = (Number) val;
      listModel.setSize(num.intValue());
      }
      }

      });

      final JCheckBox wrap = new JCheckBox("Wrap");
      wrap.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      list.setLayoutOrientation(wrap.isSelected() ? JList.VERTICAL_WRAP : JList.VERTICAL);
      }
      });

      JPanel buttonPanel = new JPanel();
      buttonPanel.add(new JLabel("Items:"));
      buttonPanel.add(spinner);
      buttonPanel.add(wrap);

      content.add(buttonPanel, BorderLayout.SOUTH);
      frame.setContentPane(content);

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

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use a different UI. The problem appears to be restricted to the Nimbus UI.

      Attachments

        Issue Links

          Activity

            People

              pardesha Pardeep Sharma
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: