JDK-6910490 : MatteBorder JScrollpane interaction
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u17
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: x86
  • Submitted: 2009-12-15
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 7
7 b97Fixed
Description
FULL PRODUCT VERSION :
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6002]

A DESCRIPTION OF THE PROBLEM :
MatteBorder causes rendering problems when used on a component within a JScrollPane if an icon is specified in the border.  If an icon is used the border, the border is painted on top of the JScrollPane headers and scroll bars.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create button or any other component in a JScrollPane.  Add a border with an icon specified instead of a color.  Set the size of the component so that scrollbars are visible.  Slide the scrollbars until the border is drawn incorrectly.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The border of a component within a JScrollPane should never be rendered on top of the JScrollBar scroll bars or headers.
ACTUAL -
The border is drawn on the scroll bars and headers.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

public class MatteBorderScrollPaneBug {
   public static void main(String[] args) {
      JButton center = new JButton("Center") {
         public Dimension getPreferredSize() {
            return new Dimension(270, 270);
         }
      };
      Icon icon = new Icon() {
         public int getIconHeight() { return 11; }

         public int getIconWidth() { return 11; }

         public void paintIcon(Component c, Graphics g, int x, int y) {
            g.setColor(Color.RED);
            g.fillRect(x + 0, y + 0, getIconWidth(), getIconHeight());
         }
      };
      JFrame frame = new JFrame();
      JScrollPane scroller = new JScrollPane(center);
      frame.getContentPane().add(scroller, BorderLayout.CENTER);
      scroller.setRowHeaderView(new JButton("HEADER"));
      center.setBorder(BorderFactory.createMatteBorder(11, 11, 11, 11, icon));
      frame.setBounds(300, 300, 300, 300);
      frame.setVisible(true);
   }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Sublcass MatteBorder.  Override paintBorder with copy of original method and comment out cg.setClip in each case.  Ensure that supplied icon does not draw outside of the component.

Comments
EVALUATION We should use the clipRect method instead of the setClip method.
2010-05-20