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.
相关文章