With everyone chipping in with their own flavors, based on other flavors, I add mine because the others locked you in with regards to positioning of the window on the selected screen.
It is simply the best. It allows you to set the location on the other screen as well.
public void setLocation( int screen, double x, double y ) {
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] d = g.getScreenDevices();
if ( screen >= d.length ) {
screen = d.length - 1;
}
Rectangle bounds = d[screen].getDefaultConfiguration().getBounds();
// Is double?
if ( x == Math.floor(x) && !Double.isInfinite(x) ) {
x *= bounds.x; // Decimal -> percentage
}
if ( y == Math.floor(y) && !Double.isInfinite(y) ) {
y *= bounds.y; // Decimal -> percentage
}
x = bounds.x + x;
y = jframe.getY() + y;
if ( x > bounds.x) x = bounds.x;
if ( y > bounds.y) y = bounds.y;
// If double we do want to floor the value either way
jframe.setLocation((int)x, (int)y);
}
Example:
setLocation(2, 200, 200);
Even allows you to pass in a percentage for the screen position!
setLocation(2, 0.5, 0); // Place on right edge from the top down if combined with setSize(50%, 100%);
screen must be larger than 0, which I am sure is a tough requirement!
To place on last, simply call with Integer.MAX_VALUE.