如何检测可用于普通窗口的主显示屏的可用部分? [英] How to detect the available part of the main display that's available for normal windows ?
问题描述
在大多数桌面环境中,您有一个或多个操作栏,有时还有停靠的窗口。
On most desktop environments, you have one ore more action bars and sometimes docked windows.
最大化的窗口将使用这些不同的未使用空间屏幕上的东西。这就是我所说的可用空间
A maximized window will used all the space that is not used by these different things on the side of the screen. That's what I'm calling the "available space"
是否有一个Java API来检测可用空间,并尽可能听取可能发生的变化? / p>
Is there a java API to detect the available space, and if possible to listen to the changes that may occur ?
推荐答案
基本思想是获取对屏幕设备的引用,并从屏幕边界中减去屏幕插图,如下所示
The basic idea is to get a reference to the screen device and subtract the screen insets from the screen bounds as follows
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
Rectangle bounds = new Rectangle(0, 0, 0, 0);
if (gd != null) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
bounds = gc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
bounds.x += insets.left;
bounds.y += insets.top;
bounds.width -= (insets.left + insets.right);
bounds.height -= (insets.top + insets.bottom);
}
现在,您的下一个问题将是确定哪个您实际想要的屏幕设备,此示例仅使用默认屏幕;)
Now, your next problem is going to be to determine which screen device you actually want, this example simple uses the default screen ;)
这篇关于如何检测可用于普通窗口的主显示屏的可用部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!