You can get the bounds of the screens relative to the big virtual desktop:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (GraphicsDevice gd : ge.getScreenDevices()) {
Rectangle bounds = gd.getDefaultConfiguration().getBounds();
System.out.println(bounds.toString());
}
for my setup this gives:
java.awt.Rectangle[x=0,y=0,width=1280,height=1024]
java.awt.Rectangle[x=1280,y=304,width=1280,height=720]
You can use this information to determine their order. E.g. if you are absolutely sure that your monitors are in a nice grid you can go fullscreen on the upper right monitor like this:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gdUpperRight = null;
Rectangle bUpperRight = null;
for (GraphicsDevice gd : ge.getScreenDevices()) {
Rectangle b = gd.getDefaultConfiguration().getBounds();
if (bUpperRight == null || b.x > bUpperRight.x || b.y > bUpperRight.y) {
bUpperRight = b;
gdUpperRight = gd;
}
}
gdUpperRight.setFullScreenWindow(myFrame);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…