Reputation: 30558
I got two monitor, one is 1440*900, another is 1920*1080. I can rearrange the monitor in many ways like that:
or like this:
Also, I can mirror the screen as well. How can I get these kind of information using pure Java only? Thanks.
Upvotes: 4
Views: 1867
Reputation: 40305
Check out GraphicsEnvironment.getScreenDevices()
, you can get the screen bounding rectangles from each device, e.g.:
GraphicsDevice[] screens = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getScreenDevices();
for (GraphicsDevice screen:screens)
System.out.println(screen.getDefaultConfiguration().getBounds());
On my dual-monitor system it displays:
java.awt.Rectangle[x=0,y=0,width=1600,height=900]
java.awt.Rectangle[x=-320,y=-1200,width=1920,height=1200]
You can use getDefaultScreenDevice()
to figure out which one is the primary monitor. There's a lot of other info you can get from a GraphicsDevice
which might be useful.
Upvotes: 8