Java setFullScreenWindow() keep on top(Java setFullScreenWindow() 保持领先)
问题描述
我正在编写一个旨在在双显示器设置上运行的应用程序,其中一个显示器上的显示"JFrame 全屏显示,另一台显示器上的控制"JFrame 向显示器发送指令.我尝试了两种设置全屏显示的不同方法;每个人的成功似乎都取决于操作系统.
I'm writing an application that is intended to be run on a dual monitor setup, with a "Display" JFrame going fullscreen on one monitor and a "Control" JFrame on the other monitor, sending instructions to the Display. I've tried two separate methods of setting the Display fullscreen; the success of each seems to depend on the OS.
display.setUndecorated(true);
display.setExtendedState(JFrame.MAXIMIZED_BOTH);
适用于 Windows,但 JFrame 隐藏在 OS X 和 Linux 的停靠栏/面板下.
Works in Windows, but the JFrame gets hidden under the dock/panels in OS X and Linux.
我的另一种方法,利用
GraphicsDevice.setFullScreenWindow(display);
适用于我尝试过的所有三种操作系统,但在 Windows 中,将控制窗口聚焦在另一台显示器上会使显示窗口隐藏,并调用
Works in all three OSes that I tried, but in Windows, focusing the Control window on the other monitor makes the Display window hide, and calling
display.setAlwaysOnTop(true);
不能解决问题.我有点偏爱 GraphicsDevice 方法,因为我不必处理 OS X 或 Linux 中的问题,我希望 Windows 问题是一个简单的解决方法.是吗?
Doesn't fix the problem. I'm kind of partial to the GraphicsDevice method because I don't have to deal with the issues in OS X or Linux, and I'm hoping that the Windows problem is a simple fix. Is it?
推荐答案
试试这个...
多屏
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
// Get size of each screen
for (int i=0; i<gs.length; i++) {
DisplayMode dm = gs[i].getDisplayMode();
int screenWidth = dm.getWidth();
int screenHeight = dm.getHeight();
}
使用 public final void setAlwaysOnTop(boolean alwaysOnTop) 将窗口置顶,如果窗口可见,这包括将窗口 toFront,然后粘贴"它到最高位置.
Use public final void setAlwaysOnTop(boolean alwaysOnTop) for putting the window on top, If the window is visible, this includes bringing window toFront, then "sticking" it to the top-most position.
这篇关于Java setFullScreenWindow() 保持领先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java setFullScreenWindow() 保持领先
- Eclipse 的最佳 XML 编辑器 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 转换 ldap 日期 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
