setLocationRelativeTo can fail if invoked soon after setLocation()

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 1.2.2
    • Affects Version/s: 1.1.6, 1.2.0
    • Component/s: client-libs
    • 1.2.2
    • generic, sparc
    • generic, solaris_2.5.1



      Name: mf23781 Date: 06/30/98


      Swing fails to move a JDialog Frame with the setLocationRelativeTo(Component c)
      method, when the component has been moved with the setLocation(int, int) method.
      This only occurs on the second attempt.

      Apparently this is in the 1.2 JCK and the test will fail unless this is fixed.

      import com.sun.java.swing.*;
      import java.awt.*;

      public class JDialogTest
      {
      public JDialogTest()
      {
      int testsX[]={0 ,100 ,Toolkit.getDefaultToolkit().getScreenSize().width , 200};
      int testsY[]={0 ,100 ,Toolkit.getDefaultToolkit().getScreenSize().height ,200};
      Point results[]={ new Point(100,100),
      new Point(200,200),
      new Point(Toolkit.getDefaultToolkit().getScreenSize().width-100,Toolkit.getDefaultToolkit().getScreenSize().height-100),
      new Point(300,300)
      };

      JFrame f= new JFrame();
      JPanel p=new JPanel();
      f.getContentPane().add(p);
      f.setSize(300,300);
      f.setLocation(0,0);
      JDialog c=new JDialog(f); // Create JDialog object
      c.setSize(100,100);
      try
      {

      f.setVisible(true);
      c.setVisible(true);

      for(int i=0;i<testsX.length;i++)
      {
      f.setLocation(testsX[i],testsY[i]);
      c.setLocationRelativeTo(p); // set location
      }
      }
      catch(Throwable e)
      {
      // Test no exceptions thrown
      c.setVisible(false);
      f.setVisible(false);
      }
      }

      public static void main(String argv[])
      {
      JDialogTest d = new JDialogTest();
      }
      }
      ======================================================================

            Assignee:
            Anne Fowler (Inactive)
            Reporter:
            Mick Fleming
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: