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

SizeRequirements.calculateTiledPositions() overflows allocated space

XMLWordPrintable

      Name: bsC130419 Date: 05/16/2001


      java version "1.3.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_02)
      Java HotSpot(TM) Client VM (build 1.3.0_02, mixed mode)

      The calculateTiledPositions() method of javax.swing.SizeRequirements
      incorrectly overflows the allocated size by a couple of pixels when the
      allocated size is less than the total preferred size of the components.

      In this example, the allocated size is 25, which is greater than the minimum
      total size of the child components (15), but less than the preferred total size
      of the components (30).

      The resulting tiled child components should then fall within the allocated
      pixel range of 0 .. 24, with a total span of 25.

      Instead, the last span returned by the method overflows the allocated size by
      two pixels, and the total of the spans returned is 27.



      /*
       * SizeRequirementsBugReport.java
       *
       * Created on May 11, 2001, 10:07 AM
       */

      import javax.swing.SizeRequirements;

      public class SizeRequirementsBugReport {

          public static void main (String args[]) {

              int allocated = 25;
              
              SizeRequirements widgets[] = new SizeRequirements[3];
              widgets[0] = new SizeRequirements(5, 10, 20, 0f);
              widgets[1] = new SizeRequirements(5, 10, 20, 0f);
              widgets[2] = new SizeRequirements(5, 10, 20, 0f);
              
              int[] offsets = new int[3];
              int[] spans = new int[3];
              
              SizeRequirements.calculateTiledPositions(allocated, null, widgets,
      offsets, spans);
              System.out.println("allocated: " + allocated);
              int totalSpan = 0;
              for (int i = 0; i < 3; ++i) {
                  System.out.println(" first pixel: " + offsets[i] +
                                     " last pixel: " + (offsets[i] + spans[i] - 1) +
                                     " (span of " + spans[i] + ")");
                  totalSpan += spans[i];
              }
              System.out.println("total span: " + totalSpan);
          }

      }



        Program output:

      allocated: 25
          first pixel: 0 last pixel: 8 (span of 9)
          first pixel: 9 last pixel: 17 (span of 9)
          first pixel: 18 last pixel: 26 (span of 9)
      total span: 27
      (Review ID: 124230)
      ======================================================================

            Unassigned Unassigned
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: