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

setClip with invalid rect changes rect to valid

XMLWordPrintable

    • 1.2.2
    • generic, x86
    • generic, solaris_2.6, windows_95



      Name: rm29839 Date: 06/11/98


      When constructing clip rectangles for graphics
      operations it is desireable to be able to
      intersect two rectangles and pass the result to
      setClip.

      If the two rectangles are disjoint
      (no intersection) then intersect returns a rect
      with a negitive width or height. If you pass
      such a rectangle to setClip, getClipBounds will
      return the same rectangle with the absolute value
      of all points in the rectangle that was passed to
      setClip.

      That can really mess up GUI code.
      import java.awt.*;
      import java.awt.image.*;
      import java.awt.geom.*;


      public class MMM extends Frame{
        public static void main (String [] args){
          new MMM();
        }
        public MMM(){
          setSize(200,200);
          show();
          validate();
        }
        
          public void paint(Graphics g){
            Rectangle r1 = new Rectangle(0,0,100,100);
            Rectangle r2 = new Rectangle(200,200,20,20);
            Rectangle r3 = r1.intersection(r2);
            System.out.println("intersect :(" + (int)r3.getX() + "," + (int)r3.getY() + "," + (int)r3.getWidth() + "," + (int)r3.getHeight() + ")" );g.setClip(r3);
            Rectangle r4 = g.getClipBounds();
            System.out.println("getClipBounds:(" + (int)r4.getX() + "," + (int)r4.getY() + "," + (int)r4.getWidth() + "," + (int)r4.getHeight() + ")" );
            
          }
        
      }
      (Review ID: 33441)
      ======================================================================

            mbronsonsunw Mike Bronson (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: