Thursday, October 4, 2012

How to display Window in the center of the screen

In Java, many of the swings applications by default opens the window at the top left corner of the screen. In addition to setting the size and making it visible, we also need to set the coordinates where the new window has to be displayed. To show the window in the center of the given screen/monitor, I have written an example explained below.

This example automatically takes the current screen resolution and depending on the size (of the window) provided, it adjusts the start point of the screen.