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

SwingUtilities.computeDifference returns rectangles outside of the given

XMLWordPrintable

    • swing1.1
    • x86, sparc
    • solaris_2.5, windows_95
    • Verified



      Name: akC57697 Date: 03/12/98



      The SwingUtilities.computeDifference() returns rectangles outside of the given.

      Javadoc says:
      "
      public static Rectangle[] computeDifference(Rectangle rectA,Rectangle rectB)

      Convenience returning an array of rect representing the regions within
                                                                      ^^^^^^
      rectA that do not overlap with rectB. If the
      two Rects do not overlap, return an empty array
      "


      -----------------------Example--------------------
      import java.awt.swing.SwingUtilities;
      import java.awt.Rectangle;
      public class SwingUtilitiesTest {
          public static void main(String s[]) {
          
        Rectangle main_rec = new Rectangle(0,0,500,500);
        Rectangle inner_rec = new Rectangle(400,200,100,100); // In the main_rec
        Rectangle result []=null;

       
        // Verify the rectangles
        if (!SwingUtilities.isRectangleContainingRectangle(main_rec,inner_rec)) {
             System.out.println("The given rectangle "+inner_rec+" out of "+main_rec);
             return;
        }

        result=SwingUtilities.computeDifference(main_rec,inner_rec);

         for (int i=0;i<result.length; i++) {
          if (!(SwingUtilities.isRectangleContainingRectangle(main_rec,result[i]))) {
             System.out.println("The "+i+"th rectangle "+result[i]+" out of "+main_rec);
             return;
          }
         }
        }
      }

      --------------------------------------------------
      Output:
      The 2th rectangle java.awt.Rectangle[x=400,y=300,width=100,height=400]
      out of java.awt.Rectangle[x=0,y=0,width=500,height=500]


      ======================================================================

            jeff Jeff Dinkins
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: