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

Synopsis: Spurious Horizontal Scroll Bar Thumb in Nimbus

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_18"
      Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
      Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)

      1.6.0_20


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]


      A DESCRIPTION OF THE PROBLEM :
      When a JScrollPane is set to always use a horizontal scroll bar,
      under certain conditions when no scroll bar is needed, the
      Nimbus look and feel will display a unnecessary thumb in a horizontal scroll
      bar at the right edge of the window. This thumb will move when dragged but
      does nothing.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Run this test on a monitor with a horizontal resolution of at least 1280
      2) Run the enclosed test program.
      3) The window will show nine JScrollPanes, with all combinations of the
      values never, always, and as-needed for both scroll bars.
      Notice the three horizontal scroll bars. They're all at the right edge of
      the screen.
      4) When the spurious thumb is visible, try dragging it to see that it
      doesn't do anything.
      5) Drag the size box to narrow the window and watch the scroll bars
      disappear as the window drops below about 1150. (You can see the size of
      the window at the bottom left corner.)
      6) Continue narrowing the window until it's too narrow to show all the text.
      Notice that the scroll bars reappear, as they should.
      7) Use the look-and-feel buttons at the left to attempt this in any other
      look and feel.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      For the three fields that say "Horizontal: Always," the scroll bar should
      only appear when the window is too narrow to show all the text in the field.
      Once the field is wide enough to show the all the text, the scroll bar
      should never show the thumb.

      ACTUAL -
      Most looks-and-feels work as expected. The bug only shows up in Nimbus.
      When the field gets too wide, the scroll bars appear again. This happens at
      a width of about 1150 pixels. (It happens at a slightly different width for
      the first scroll bar, because that pane doesn't have a vertical scroll bar,
      which changes the width of the horizontal scroll bar.)
      It may well happen with vertical scroll bars, but my screen isn't big enough
      to test that case.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import java.awt.GridLayout;
      import java.awt.Rectangle;
      import java.awt.event.ActionEvent;
      import java.awt.event.ComponentAdapter;
      import java.awt.event.ComponentEvent;
      import java.awt.event.ComponentListener;
      import java.util.*;
      import javax.swing.*;
      import javax.swing.plaf.metal.OceanTheme;
      import javax.swing.plaf.metal.MetalLookAndFeel;
      import javax.swing.plaf.metal.DefaultMetalTheme;

      @SuppressWarnings({"HardCodedStringLiteral", "HardcodedLineSeparator", "MagicCharacter", "StringConcatenation", "MagicNumber", "StringContatenationInLoop", "ObjectAllocationInLoop"})
      public class NimbusScrollBarBug extends JPanel {
      private static JFrame sMainFrame;

      private static JLabel sizeLabel = new JLabel();

      public static void main(String[] args) {
      makeFrame(LandF.Nimbus);
      }

      private static void makeFrame(LandF landf) {
      Rectangle oldBounds = null;
      if (sMainFrame != null) {
      oldBounds = sMainFrame.getBounds();
      sMainFrame.dispose();
      }
      landf.install();
      sMainFrame = new JFrame("NimbusScrollBarBug");
      sMainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      sMainFrame.add(new NimbusScrollBarBug(), BorderLayout.CENTER);
      sMainFrame.add(makeLandFButtons(), BorderLayout.WEST);
      if (oldBounds == null)
      sMainFrame.setBounds(10, 10, 1200, 325);
      else
      sMainFrame.setBounds(oldBounds);
      sMainFrame.add(sizeLabel, BorderLayout.SOUTH);
      setSizeLabel();
      sMainFrame.setVisible(true);

      ComponentListener cl = new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e) {
      setSizeLabel();
      }
      };
      sMainFrame.addComponentListener(cl);
      }

      private static void setSizeLabel() {
      Dimension mainSize = sMainFrame.getSize();
      sizeLabel.setText(String.format("Size: (%d x %d)", mainSize.width, mainSize.height));
      }

      public NimbusScrollBarBug() {
      super(new GridLayout(0, 1));

      Map<Integer, String> verticalStates = new HashMap<Integer, String>();
      verticalStates.put(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, "Vertical: As Needed. ");
      verticalStates.put(JScrollPane.VERTICAL_SCROLLBAR_NEVER, "Vertical: Never. ");
      verticalStates.put(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, "Vertical: Always. ");

      Map<Integer, String> horzStates = new TreeMap<Integer, String>();
      horzStates.put(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED, "Horizontal: As Needed.");
      horzStates.put(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER, "Horizontal: Never.");
      horzStates.put(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS, "Horizontal: Always.");

      for (Integer vKey: verticalStates.keySet()) {
      for (Integer hKey: horzStates.keySet()) {
      JTextArea ta = new JTextArea();
      JScrollPane scr = new JScrollPane(ta, vKey, hKey);
      setText(ta, verticalStates.get(vKey) + ' ' + horzStates.get(hKey));
      add(scr);
      }
      }
      }

      private void setText(JTextArea cmp, String text) {
      cmp.setText(text + '\n' + text + '\n' + text + '\n' + text + '\n' + text + '\n' + text);
      }

      private static JPanel makeLandFButtons() {
      JPanel pnl = new JPanel(new GridLayout(0, 1));
      LandF[] all = LandF.values();
      for (LandF lf : all)
      pnl.add(new JButton(lf.getAction()));
      pnl.add(new JLabel(System.getProperty("java.version"))); // NON-NLS
      JPanel outerPanel = new JPanel();
      outerPanel.add(pnl);
      return outerPanel;
      }

      private enum LandF {
      Platform(UIManager.getSystemLookAndFeelClassName()),
      Metal(MetalLookAndFeel.class.getName()),
      Ocean(UIManager.getCrossPlatformLookAndFeelClassName()),
      Motif(com.sun.java.swing.plaf.motif.MotifLookAndFeel.class.getName()),
      Nimbus(com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel.class.getName()),
      ;
      final private String mName;
      private Action mAction;

      LandF(String name) {
      mName = name;
      mAction = new LandFAction(this);
      }

      public String getLFName() { return mName; }

      public void install() {
      //noinspection CatchGenericClass
      try {
      UIManager.setLookAndFeel(getLFName());
      extra();
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      public Action getAction() {
      return mAction;
      }

      private void extra() throws UnsupportedLookAndFeelException {
      if (this == Metal) {
      MetalLookAndFeel lf = (MetalLookAndFeel) UIManager.getLookAndFeel();
      lf.setCurrentTheme(new DefaultMetalTheme());
      UIManager.setLookAndFeel(lf); // set it again
      } else if (this == Ocean) {
      MetalLookAndFeel lf = (MetalLookAndFeel) UIManager.getLookAndFeel();
      lf.setCurrentTheme(new OceanTheme());
      UIManager.setLookAndFeel(lf); // set it again
      }
      }
      }

      @SuppressWarnings({"serial"})
      private static class LandFAction extends AbstractAction {
      private LandF mLookAndFeel;

      public void actionPerformed(ActionEvent e) { makeFrame(mLookAndFeel); }

      LandFAction(LandF lAndF) {
      super(lAndF.toString());
      mLookAndFeel = lAndF;
      }
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Don't use Nimbus.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: