REGRESSION: Window.setLocationRelativeTo() does not conform to spec

XMLWordPrintable

    • generic
    • generic

      Specification for Window.setLocationRelativeTo() states (at least for java 6):

         If the component is not currently showing, or c is null, the window is placed at
         the center of the screen. The center point can be determined with
         GraphicsEnvironment.getCenterPoint()

      When the following code:

              JFrame frame = new JFrame("Invisible Frame");
              frame.setSize(new Dimension(300,300));
              frame.setLocation(0, 0);

              JDialog dialog = new JDialog();
              dialog.setSize(new Dimension(100,100));
              dialog.setLocationRelativeTo(frame.getContentPane());
              System.out.println(dialog.getLocation());


              System.out.println("Center point: " +
                      GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint());


      is run on sun jdk6 produces:
       java.awt.Point[x=590,y=350]
       Center point: java.awt.Point[x=640,y=400]
      and when the same code is run on openjdk6:
       java.awt.Point[x=590,y=350]
       Center point: java.awt.Point[x=640,y=388]
      [Note: gnome-panel is located on the bottom of screen]

      As you can see graphics environment make a correction of center point, to
      take into account gnome panel's size, but dialog is still located in the
      center of screen, so specification is violated

            Assignee:
            Unassigned
            Reporter:
            Alexey Vishentsev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: