I am collecting the screen devices of a multi-monitor environment in Java and would like to know which of these screen devices is the default screen device.
我正在收集Java中多监视器环境的屏幕设备,并想知道哪些屏幕设备是默认的屏幕设备。
The code device.getIDString()
returns "\Display0" and so forth for each monitor, so I could simply say something along the lines of .contains("0")
, but not only is this inelegant, but also I suspect that the format will be different across different vendors or operating systems.
代码device.getIDString()为每个监视器返回“\ Display0”等等,所以我可以简单地说一下.contains(“0”)的内容,但不仅仅是这个不优雅,而且我怀疑不同供应商或操作系统的格式会有所不同。
1 个解决方案
#1
The Javadoc recommends this:
Javadoc建议:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = ge.getDefaultScreenDevice();
http://docs.oracle.com/javase/7/docs/api/java/awt/GraphicsEnvironment.html#getDefaultScreenDevice()
#1
The Javadoc recommends this:
Javadoc建议:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = ge.getDefaultScreenDevice();
http://docs.oracle.com/javase/7/docs/api/java/awt/GraphicsEnvironment.html#getDefaultScreenDevice()