如何让swing应用知道屏幕尺寸的变化?

Mar*_*ond 6 java size swing screen toolkit

当我的swing应用程序运行时,我改变了屏幕的大小(例如从1024x768到800x600).

我有什么事情可以收听通知吗?

或者,我可以在每隔几秒检查屏幕大小,但Toolkit.getScreenSize()会不断告诉我旧值.
如何在更改后获得真正的屏幕尺寸?

环境:Linux(在SuSE ES 11和Ubuntu 9.04上测试)

我感谢您的帮助.
马顿

Jus*_*ick 2

以下内容对我有用,但我使用的是 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());
Run Code Online (Sandbox Code Playgroud)

输出(blah实际上是输入)如下:

1440x900
Waiting on input, go change your resolution
blah
1280x960
Run Code Online (Sandbox Code Playgroud)

显然,如果您有多个屏幕设备,则必须更加小心。