Friday, 27 September 2013

Map physical screen position to an array of GraphicsDevice with Swing

Map physical screen position to an array of GraphicsDevice with Swing

In Windows, each screen has an number or identity assigned I assume is
relative to how I physically connected my monitor cables. Key to my
question is that I can reconfigure these screens but they will keep their
identity.
Java's call to
GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() will
give me an array of GraphicsDevice.
How can I correlate the order of screens in the array with the Window
numbering? I'd be interested in a cross-platform solution.
For example, my Windows configuration looks like this
but the array returned looks like this
screens[0] = relates to screen 2
screens[1] = relates to screen 3
screens[2] = relates to screen 1
So the physical
NB the code I get I'd like to use is along the lines of this
frame.setLocation(
screens[i].getDefaultConfiguration().getBounds().x, frame.getY());
where i should be the physical number and not the position in the array
(or its mapping if you see what I mean).

No comments:

Post a Comment