How to create a "virtual device environment" in Java to work with multiple monitors?
The method getScreenDevices() of Graphic开发者_如何学JAVAsEnvironment must return a list of GraphicsDevice in my system. How can I configure my system to work with these GraphicsDevice, beforehand?
As long as you have the monitors hooked up and enabled in the operating system, Java will detect them. Consider this code:
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = env.getScreenDevices(); Rectangle[] screenBounds = new Rectangle[devices.length]; for (int x = 0; x < this.devices.length; x++) { GraphicsConfiguration conf = this.devices[x].getDefaultConfiguration(); screenBounds[x] = conf.getBounds(); }
You can also investigate Toolkit.getDefaultToolkit().getScreenInsets(configuration)
to get a list of insets so you know, for example, where the start bar is.
Be warned, however, that if you try to do this under certain X windows environments, the insets are not available. I worked around this problem by creating an invisible frame on each screen, maximizing them, waiting for them to generate a resize event, and then grabbing their bounds and disposing of them. But I only trigger this code if I get zero insets from all the monitors.
If I understand well your question, and you want to create a "virtual device" here is an answer :
As the GraphicsEnvironment uses system properties to access the available devices, you would have to modify your JVM or trick the system to make it thinks it has another device.
精彩评论