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

[macosx] Frame setLocationByPlatform has no effect under Mac OS X

XMLWordPrintable

    • b127
    • os_x

      FULL PRODUCT VERSION :
      java version "1.7.0_40"
      Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
      Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Darwin 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      Calling the setLocationByPlatform method on a java.awt.Frame instance doesn't have any effect.

      REGRESSION. Last worked in version 6u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the FrameLocationByPlatformTest application below and observe the location of the opened frames.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected the frames would not cover each other, the second one being shifted.
      ACTUAL -
      The two frames are located at the same place.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class FrameLocationByPlatformTest {
        public static void main(String [] args) {
          java.awt.Frame frame1 = new java.awt.Frame("Frame 1");
          frame1.setSize(500, 300);
          frame1.setLocationByPlatform(true);
          frame1.setVisible(true);

          java.awt.Frame frame2 = new java.awt.Frame("Frame 2");
          frame2.setSize(500, 300);
          frame2.setLocationByPlatform(true);
          frame2.setVisible(true);
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Change the location of the frame according to the location of all the opened frames and shift it yourself, for example with some code similar to the following:

      int minX = Integer.MAX_VALUE;
      int minY = Integer.MAX_VALUE;
      int maxX = Integer.MIN_VALUE;
      int maxY = Integer.MIN_VALUE;
      for (Frame otherFrame : Frame.getFrames()) {
        if (otherFrame.isShowing()) {
          minX = Math.min(minX, otherFrame.getX());
          minY = Math.min(minY, otherFrame.getY());
          maxX = Math.max(maxX, otherFrame.getX());
          maxY = Math.max(maxY, otherFrame.getY());
        }
      }

      if (minX == Integer.MAX_VALUE || minX >= 23) {
        x = 0;
      } else {
        x = maxX + 23;
      }
      if (minY == Integer.MAX_VALUE || minY >= 23) {
        y = 0;
      } else {
        y = maxY + 23;
      }
      // Set the location of the new frame
      frame.setLocation(x, y);

            dmarkov Dmitry Markov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: