JDK-4192403 : Graphics.clipRect() clips incorrectly when rects don't intersect
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1998-11-24
  • Updated: 1999-09-16
  • Resolved: 1999-09-16
Related Reports
Duplicate :  
Description

Name: gsC80088			Date: 11/23/98


/* The following panel clipps its
 * graphics to the lower half and
 * upper quarter, so nothing should
 * be painted. But, see the result:
 * the clipping before and after
 * transforming are not compatible.
 * In my application this bug results
 * in false drawing on a columnheader
 * of a JScrollPane.
 *
 * Clear the // at the two lines
 * before scaling and add // to the
 * two lines after scaling, and every-
 * thing works fine. Add // to the line
 * where the graphics is scaled and
 * the result is correct, too.
 */

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

public class Test extends JPanel {

  int zoom = 1;

  public static void main (String[] argv){
    JFrame frame = new JFrame();
    frame.setContentPane (new Test ());

    frame.addWindowListener (new WindowAdapter (){
      public void windowClosing (WindowEvent e){
        System.exit (0);
      }
    });

    frame.setSize (256,512);
    frame.setVisible (true);
  }

  public void paint (Graphics g){
    Rectangle clip = g.getClipBounds ();
    g.setColor (Color.gray);
    g.fillRect (clip.x, clip.y,
                clip.width, clip.height);

    // clipping graphics to lower half of panel
    g.clipRect (clip.x, clip.y + clip.height / 2,
                clip.width, clip.height / 2);

    Graphics2D g2D = (Graphics2D) g;

    // clipping graphics to upper quarter of panel ...
    // ... before scaling is false!
//    g2D.clipRect (clip.x, clip.y,
//                  clip.width, clip.height / 4);

    g2D.scale (zoom, zoom);

    // clipping graphics to upper quarter of panel ...
    // ... after scaling is wrong !!
    g2D.clipRect (clip.x / zoom, clip.y / zoom,
                  clip.width / zoom, clip.height / (zoom * 4));

    // filling a rectangle should result in nothing
    g2D.setColor (Color.white);
    g2D.fillRect (clip.x / zoom, clip.y / zoom,
                  clip.width / zoom, clip.height / zoom);
  }
}
(Review ID: 43206)
======================================================================

Name: rlT66838			Date: 08/27/99


This bug is hidden and needs to be fixed. It is causing problems for JScrollPane GUI that take advantage of rowHeader and columnHeader. 

It surfaces only when setpreferredSize is called manually to increase and multiply the width of a JScrollPane view.

Inside a JScrollPane I double the width of the view with setPreferredSize(). Upon subsequent entry into rowHeader or columnHeader paintComponent() methods I call getClipBounds().

The clip I get back has the origin decremented from the extent for either the X or Y axis.

I manually resize the frame and then subsequent entry into the paint method's of these components provides a good clip region.

I do not need to provide a reproducable demo. 

BUG 4192403 already has ont and this still has not been addressed.

Take note that the person that submitted 4192403 is trying to implement zoom. I am implementing zoom by multiplying the width of the view. Whoever is responsible for setting the clip for the Graphics object is not doing what they are suppose to. They forgot to take into account increased dimensions of the VIEW as it relates to the ROWHEADER and COLUMNHEADER.

Please advise... a work around is critical.

We need a workaround immediately.
(Review ID: 94532)
======================================================================

Name: skT88420			Date: 08/31/99


Upon directly accessing the JScrollPane's columnHeader view... via JScrollPane derivative, 

columnHeader.putClientProperty("EnableWindowBlit", Boolean.TRUE);

Causes the ClipBounds of the columnHeader view to be corrupted with huge negative window width and window height thus disrupting the paint of the component. -2147483547 is a sample of huge for the width.

SUN continues to ignore this bug and refuses to provide support or workaround.

This is caused after the JScrollPane's viewport view's preferredSize is modified dynamically to be bigger.

Refer to BUG 4192403
(Review ID: 94665)
======================================================================

Comments
WORK AROUND Name: skT88420 Date: 08/31/99 None (Review ID: 94665) ======================================================================
11-06-2004

EVALUATION This is a dup of 4147957. Also, since the Graphics2D class did not exist before 1.2, the customer call records indicating release 1.1.8 must be incorrect so I changed them to read 1.2. jim.graham@Eng 1999-09-15
15-09-1999