By default, my Swing program starts at the top left hand side of the monitor. Is there a way to make it so it pops up at the right hand side?
What about dual monitors? Can I get it to pop on the right monitor?
Thanks.
Carlo
By default, my Swing program starts at the top left hand side of the monitor. Is there a way to make it so it pops up at the right hand side?
What about dual monitors? Can I get it to pop on the right monitor?
Thanks.
Carlo
Assuming you don't want to cover up the taskbar, you should use getMaximumWindowBounds.
http://www.javabeginner.com/java-swing/java-jframe-class-example
Centering JFrame’s
By default, a Jframe is displayed in the upper-left corner of the screen. To display a frame at a specified location, you can use the setLocation(x, y) method in the JFrame class. This method places the upper-left corner of a frame at location (x, y).
Your pseudo code for the top right corner looks something like this:
yourJFrame.setLocation(
GraphicsEnvironment.getMaximumWindowBounds().getWidth() -
yourJFrame.getWidth(), 0);
For displaying at another initial location, take a look at JFrame.setLocation()
For displaying on another screen, take a look at avaible infos from GraphicsEnvironment.getScreenDevices()
.
There are many questions/answers about using GraphicsEnvironment
to do similar things.
You can use GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
to get all the monitors, then call GraphicsDevice#getConfigurations
and then GraphicsConfiguration#getBounds
to get the size and location of each monitor, then use your high-school geometry to find the "right" monitor. (Note that a true multi-monitor setup can put them in arbitrary location.)