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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Frame f = new MyFrame();
f.setSize(500, 300);


  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);
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.
 w.setLocation(100, 100);

  w.setBounds(100, 100, 500, 300);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.