Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect the screen position in a system with multiple displays?

I got two monitor, one is 1440*900, another is 1920*1080. I can rearrange the monitor in many ways like that:

enter image description here

or like this:

enter image description here

Also, I can mirror the screen as well. How can I get these kind of information using pure Java only? Thanks.

like image 804
DNB5brims Avatar asked Oct 28 '25 14:10

DNB5brims


1 Answers

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.

like image 192
Jason C Avatar answered Oct 31 '25 03:10

Jason C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!