I'm doing a form with several layout's and I want, when executing the code, that form on the center of the screen.
How can I do that ?
Printable View
I'm doing a form with several layout's and I want, when executing the code, that form on the center of the screen.
How can I do that ?
You are crating the form in HTML/JSP..?
This works fine
good luckCode:public static void centerFrame(JFrame frame) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Point center = ge.getCenterPoint();
Rectangle bounds = ge.getMaximumWindowBounds();
int w = Math.max(bounds.width/2, Math.min(frame.getWidth(), bounds.width));
int h = Math.max(bounds.height/2, Math.min(frame.getHeight(), bounds.height));
int x = center.x - w/2, y = center.y - h/2;
frame.setBounds(x, y, w, h);
if (w == bounds.width && h == bounds.height)
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.validate();
}