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
Use
public final void setAlwaysOnTop(boolean alwaysOnTop)
for putting the window on top, If the window is visible, this includes bringing windowtoFront
, then "sticking" it to the top-most position.I run across the same problem. My way to solve it was to override the
show()
function in the jframe and by using a buffer strategy never return out of the show function. Thus something like this:It would actually be better if one used
setVisible(boolean)
instead ofshow()
(show
is deprecated). The window won't always be on top (you can still drag another window on top of it), but it won't automatically hide when you give focus to another window. That is the behaviour you want I guess.Note: Do not call
show
in the eventqueue, as this will render the eventqueue useless, and makes the jframe ignore all events. The functionshow
should be called in a new thread, then all events will still be handled.