java让弹窗在最上层,Java setFullScreenWindow()保持在最顶层

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);

Works in Windows, but the JFrame gets hidden under the dock/panels in OS X and Linux.

My other method, utilizing

GraphicsDevice.setFullScreenWindow(display);

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);

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?

解决方案

Try this...

For Multiple Screen

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice[] gs = ge.getScreenDevices();

// Get size of each screen

for (int i=0; i

DisplayMode dm = gs[i].getDisplayMode();

int screenWidth = dm.getWidth();

int screenHeight = dm.getHeight();

}

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值