【发布时间】:2015-07-30 07:32:43
【问题描述】:
我从 this question 了解到,您可以使用以下代码在 swing 应用程序中以 GraphicsDevice[] 的形式获取当前显示:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices();
我知道从这里我可以自己设置设备,让用户在菜单中选择要使用的设备,等等。我的目标是检测应用程序当前显示在哪些 GraphicsDevices 中,所以我可以默认为全屏在当前的 GraphicsDevice 中,而不会打扰用户。
我正在使用如下代码来全屏显示我的应用程序:
JFrame frame = new JFrame();
// ... when I want to fullscreen:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
if (gd.isFullScreenSupported()){
frame.dispose();
frame.setUndecorated(true);
frame.setAlwaysOnTop(true);
gd.setFullScreenWindow(frame);
frame.setVisible(true);
}
我在 GraphicsDevice 或 GraphicsEnvironment API 中找不到任何东西来获取显示 JFrame 的当前 GraphicsDevice。我知道直接定位窗口可能会有黑客攻击(如上面的链接中所述),但我想知道是否有更简单/更优雅的解决方案。
【问题讨论】:
-
一般我只用
GraphicsDevices的GraphicsConfigurations来测试Window是否在设备的范围内,对于example -
太棒了,所以我可以测量窗口与最大区域重叠的设备?
-
是的,示例 (
getGraphicsDevice(Component)) 也是这样做的 ;) -
查看 Santhosh 的回答。可以完美运行,就像您编写的代码示例一样(也可以),但是当它已经在 API 中时,为什么要重新发明轮子呢?
-
可能的原因是它要么没有做我想要的,要么没有返回我想要或预期的结果
标签: java swing jframe fullscreen