当我的 swing 应用程序运行时,我更改屏幕尺寸(例如从 1024x768 更改为 800x600)。
我可以收听任何活动以获得有关此事件的通知吗?
或者,我可以每隔几秒检查一次屏幕尺寸,但 Toolkit.getScreenSize() 不断告诉我旧值。
更改后如何获得真实屏幕尺寸?
环境:Linux(在SuSE ES 11和Ubuntu 9.04上测试)
我感谢您的帮助。
Marton
以下内容对我有用,但我使用的是 Mac,所以我不能肯定它在 Linux 上也能工作:
System.out.println(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDisplayMode().getWidth() + "x" + GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDisplayMode().getHeight());
//Ignore this block, it was simply to give me a chance to change my resolution
Scanner readUserInput=new Scanner(System.in);
System.out.println("Waiting on input, go change your resolution");
String myName=readUserInput.nextLine();
System.out.println(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDisplayMode().getWidth() + "x" + GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDisplayMode().getHeight());
输出(blah实际上是输入)如下:
1440x900
Waiting on input, go change your resolution
blah
1280x960
显然,如果您有多个屏幕设备,则必须更加小心。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)