I've written a Swing application. I want to set the JFrame
to be centred in the user's screen. I can set it to the approximate center of my screen using:
JFrame frame = new JFrame("Test Frame");
Rectangle r = new Rectangle(600, 300, 400, 400);
frame.setBounds(r);
Is there a way to define the Rectangle r
such that the center of it is at the center of any screen?
Is setBounds()
the wrong method for varying the frame position dynamically?