frame display

whenever I intantiate and make visible a new frame or a dialog box, it appears in the upper left corner of the screen. Is it any way where I could make the frame appear at the screen position I want, say at the center.
qader99Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
heyhey_Connect With a Mentor Commented:
 w.setLocation(100, 100);

or
  w.setBounds(100, 100, 500, 300);
0
 
heyhey_Commented:
Frame f = new MyFrame();
f.setSize(500, 300);
centerWindow(f);
f.setVisible(true);

where

  public static void centerWindow(Window w)
  {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = w.getSize();
    int left = screenSize.width/2 - windowSize.width/2;
    int top = screenSize.height/2 - windowSize.height/2;
    w.setLocation(left, top);
  }
 
0
 
qader99Author Commented:
Thank you heyhey
           the above code works perfectly well.

          what if I want to show the frame at the particular
screen position or coordinates.
0
All Courses

From novice to tech pro — start learning today.