Hi,
I want a JFrame to always appear at the center of the screen. Is there a way to achieve this?
Regards,
Hiranya
Printable View
Hi,
I want a JFrame to always appear at the center of the screen. Is there a way to achieve this?
Regards,
Hiranya
Code:// Get the size of the screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Determine the new location of the window
int w = window.getSize().width;
int h = window.getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
// Move the window
window.setLocation(x, y);
If you are using j2se 1.4+ you have access to the Window method
setLocationRelativeTo(Component c). Use null for the argument to center your top–level container.
use this.setLocationRelativeTo(getRootPane());
Something useful to a rotten dead thread which has been answered three years ago? Come on.
It was usefull. It told anyone reading this posting to ignore that suggestion.Quote:
Perhaps you could have tried adding something useful, rather than just "Eejit"?
The proper solution has already been given so there was no need to repeat it.
Why don't you try (as a new member to the forum) to contribute something positive.
Locking thread.