Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

swing - Java setFullScreenWindow() keep on top

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this...

For Multiple Screen

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...