It depends a bit how you did set up your second monitor. For my answer, I'm assuming that you added it as an "extension" to your desktop (so you can move windows between them by dragging with the mouse).
In this mode, your desktop becomes bigger. To see that, call GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds
.
The width should be the sum of the widths of your two monitors and the height should be the larger of the two heights.
Note that the x coordinate can be < 0 (this happens if your make the right monitor the default one).
To move your window to the other monitor, simply use a position (setPosition()
) with an appropriate value and pass that position as an option to the program. Or save the current position as a preferences node and open the window again in the same place when the app is run again.
If your monitors are configured independently, you should look into the GraphicsEnvironment.getScreenDevices()
API.