0 votes
1 view
in Java by (3.9k points)

While working with Java, I find it hard to position my main window in the center of the screen when I start the application.

Is there any way I can do that? It doesn't have to be vertically centered, horizontal alignment is the more important goal for me. But vertical alignment is also welcome.

1 Answer

0 votes
by (41.5k points)

I always did it in this way:

Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);

where this is the JFrame involved.

Related questions

0 votes
1 answer
0 votes
1 answer
asked 2 hours ago in Java by Anvi (8.5k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...