3

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.

Jason C
  • 38,729
  • 14
  • 126
  • 182
DNB5brims
  • 29,344
  • 50
  • 131
  • 195
  • 1
    Pretty sure only the Display Driver will have this kind of information. Think this is the best you can do in Java: http://stackoverflow.com/questions/877570/java-getting-resolutions-of-one-all-available-monitors-instead-of-the-whole-de – Durandal Feb 28 '14 at 05:30
  • @JasonC Yeah I don't know that regular Java can do much beyond what we posted; Android has far more of support for that kind of thing but don't think that qualifies as 'pure java' – Durandal Feb 28 '14 at 05:36
  • @Durandal Oh, good link. Yeah, you can do what's in that link, essentially, except you can use `getDefaultConfiguration().getBounds()` to get actual relative coordinates of the monitors; you could actually use it to generate the picture TedWong posted, if you wanted. – Jason C Feb 28 '14 at 05:36
  • Whoops, sorry, my clumsy editing made our comments collide. – Jason C Feb 28 '14 at 05:37

1 Answers1

7

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.

Jason C
  • 38,729
  • 14
  • 126
  • 182
  • ok Jason thanks... this at least helping me out to recognized how many monitors currently available. Hehe... great! – gumuruh Apr 06 '22 at 23:49