JWindow Inject in Desktop

44 Views Asked by At

Can anyone show example on how to make a JWindow always on Desktop? I cannot set the "AlwaysOnTop" since I do not want it to be on top of other applications, but I want it to stay on Desktop.

Whenever I click the show Desktop button or Windows Key + M to minimize all, it disappears also. When i return to any window, it will be visible again.

I wanted to inject the window in the desktop.

1

There are 1 best solutions below

2
STaefi On

I cannot understand what do you mean by "I wanted to inject the window in the desktop." but if you want to prevent your application window from being minimized (ICONIFIED), you can write a small WindowStateListener and in the windowStateChanged check for the new state of your window. If its new state was ICONIFIED you can change the state to NORMAL again:

public static void main(String[] args) {
    final JFrame jf = new JFrame();
    jf.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent e) {
            System.out.println(e.getNewState());
            if(e.getNewState() == JFrame.ICONIFIED) {
                jf.setExtendedState(JFrame.NORMAL);
            }
        }
    });
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setBounds(100, 100, 300, 300);
    jf.setVisible(true);
}

It will support your windows+M hot key, because after minimizing all windows, your application's window will be deiconified.

Hope this help.