سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top