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

Window.setLocationRelativeTo(Component) broken for non-xinerama multi-head sys

    XMLWordPrintable

Details

    • b19
    • sparc
    • solaris_8
    • Not verified

    Description

      FULL PRODUCT VERSION :
      java version "1.5.0_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)
      (others)

      ADDITIONAL OS VERSION INFORMATION :
      Solaris 8
      Red Hat Linux Fedora Core 4
      (at least)

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Non-xinerama X-windows configuration.

      A DESCRIPTION OF THE PROBLEM :
      calling the Window.setLocationRelativeTo(Component) method on a window located on a screen different from that of the supplied Component results in the window being placed on the screen it was originally created on (though at a seemingly correct relative location). If, for example, a JDialog is created using a null owner and is subsequently displayed, it will always appear on the same screen as its (invisible) owner frame. This prevents re-use of dialogues in multiple head systems as they may appear on the wrong screen.

      So, either Window.setLocationRelativeTo(Component c) is broken, or the API docs need to state this limitation.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JFrame on the non-default screen. Create an ownerless JDialog. Call the dialog's setLocationRelativeTo method, passing it the JFrame. Call the JDialog's setVisible(true) method.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      dialog appears centered on JFrame
      ACTUAL -
      dialog appears on default screen (not the screen JFrame is on)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;
      import java.awt.event.*;

      public class TestCase {
              public TestCase() {
                      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                      GraphicsDevice[] gs = ge.getScreenDevices();

                      if (gs.length<2) {
                              System.out.println("Not multi-head environment, test not valid!");
                              System.exit(1);
                      }

                      final JDialog dialog=new JDialog();
                      JButton button=new JButton("Close");
                      button.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                      dialog.dispose();
                              }
                      });
                      dialog.getContentPane().add(button);
                      dialog.pack();

                      for (int i=0; i<gs.length; i++) {
                              JFrame frame=new JFrame("Frame "+i,gs[i].getDefaultConfiguration());
                              button=new JButton("Open Dialog");
                              button.addActionListener(new ButtonActionListener(frame,dialog));
                              frame.getContentPane().add(button);
                              frame.pack();
                              frame.show();
                      }
              }
              private static class ButtonActionListener implements ActionListener {
                      JFrame frame;
                      JDialog dialog;
                      public ButtonActionListener(JFrame frame,JDialog dialog) {
                              super();
                              this.frame=frame;
                              this.dialog=dialog;
                      }
                      public void actionPerformed(ActionEvent e) {
                              dialog.setLocationRelativeTo(frame);
                              dialog.show();
                      }
              }
              public static void main(String args[]) {
                      new TestCase();
              }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Do not re-use dialogs across different screens. Do not create ownerless dialogs.

      Attachments

        Issue Links

          Activity

            People

              art Artem Ananiev (Inactive)
              dav Andrei Dmitriev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: