以下代码表现得很奇怪。在IntelliJ中,控制台文本为
'3840'
with gradle编译的jar文件显示
'1920'
我有一个双显示器,都是全高清的
public void getScreenSize() {
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
System.out.println(graphicsDevices[0].getDisplayMode().getWidth());
}
答案 0 :(得分:-1)
嗯,我没有发现问题所在。但是我写了一个小的解决方法来计算主监视器的大小。请记住,此代码仅在监视器都具有相同的解决方案时才起作用:
public static Dimension getScreenSize() {
Dimension returnValue = Toolkit.getDefaultToolkit().getScreenSize();
double height = returnValue.getHeight();
double width = returnValue.getWidth();
int screenNumbers = (int) Math.ceil(width/height)/2;
if (screenNumbers != 1){
width /= screenNumbers;
}
returnValue = new Dimension((int)width, (int)height);
return returnValue;
}