In java one can get the current graphics environment using
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
and than loop through the devices using
GraphicsDevice[] screenDevices = graphicsEnvironment.getScreenDevices();
for (int i = 0; i < screenDevices.length; i++) {
GraphicsDevice graphicsDevice = screenDevices[i];
...
}
But the number of GraphicDevice
s can change at runtime, e.g. by plugging in an USB-monitor. Or the user can change a GraphicsDevice
's resolution or move it relative to another graphics device if there are multiple monitors.
How can I listen to changes of the GraphicsEnvironment
and the GraphicDevice
s?
EDIT
I tried to implement the change detection using a daemon thread that inspects the graphics environment at a specific interval, but it doesn't work.
It doesn't work because the GraphicsEnvironment
is hold in a statc variable and initialized only once.
Also the sub classes of GraphicsEnvironment
cache the GraphicDevice
s. So new GraphicDevice
s will only be detected if the jvm process is restarted.