开发者

ALWAYS on top window

开发者 https://www.devze.com 2023-01-04 04:48 出处:网络
I\'m searching 开发者_运维技巧for a solution in order to keep a JFrame always on top and with always I really mean always.

I'm searching 开发者_运维技巧for a solution in order to keep a JFrame always on top and with always I really mean always.

setAlwaysOnTop( true );

This won't work when I'm starting a game in fullscreen mode. I know you normally don't want your windows to stay on top but in this case it's required.


This can't be done.

For example, the Windows Task Manager, even when set to Always on Top will get covered up by full-screen applications.

This is due to the fact that full-screen applications typically use a different graphics context and can't be overlayed.


Start another process to check if the window is on top,if not, set it on top.


This sounds like the kind of question that Raymond Chen always has to answer over at http://blogs.msdn.com/b/oldnewthing/. How can you really really forever and for true keep a window in the foreground? You can't. Because what happens if somebody ELSE's window uses the same trick to keep itself always always and forever in the foreground? Which one wins?


This is a sample code that should be helpful

public class AllWaysOnTop extends JFrame implements WindowListener {

    AllWaysOnTop() {
        // Code to setup your frame
        addWindowListener(this);
        // Code to show your frame
    }

    // The window event handlers. We use WindowDeactivated to
    // try and keep the splash screen on top. Usually only keeps
    // the splash screen on top of our own java windows.
    public void windowOpened(WindowEvent event){};
    public void windowActivated(WindowEvent event){};
    public void windowDeactivated(WindowEvent event){
        toFront();
    }
    public void windowIconified(WindowEvent event){};
    public void windowDeiconified(WindowEvent event){};
    public void windowClosed(WindowEvent event){};
    public void windowClosing(WindowEvent event) {};
}

Reference This forum post


If you mean fullscreen as in DirectX/OpenGL/whatever, I'm not sure you can (or should) really pull it off. Most operating systems disable their native windowing during full screen to improve rendering performance. Swing works via the native windowing toolkit.

You could write something that uses a timer and in short intervals (e.g., 200ms) instructs your window to go to the top. Depending on your operating system this would be exactly what you need, or a horrible cause of performance trouble or flickering.


I'm not sure but i would bet that the Fullscreen window also has Always On Top set to true, and in that case you have stumbled into the realm of undefined behavior. In general when two windows are set to always on top there is no guarantee about ordering. I think in general though the order is just dependent on the order in which they were set to always on top. So in that case i would just wait until the app has gone fullscreen to set it to always on top and see if that works.

In other cases ive seen people start threads and then occasionally reset the fram to always on top.

All these solutions are ugly, so just use the one that lets you sleep at night.


I know this post is old, but I encountered this problem and I found a satisfying solution. My program has some notifications that I wish to be always on top, but when a movie entered full-screen, they disappeared. Fortunate, my program updates these notifications every 5 seconds, and if I call setVisible(true) on these JWindows, at each update, they regain the top position, if they have lost it.


I was looking to do the same thing as OP, have my app running in the foreground while my game ran. It doesn't work in fullscreen but if you put the game into windowed mode and adjust the window settings to fit your tv it works. I only needed the frame.setAlwaysOnTop to make it work.

0

精彩评论

暂无评论...
验证码 换一张
取 消