Search code examples
javaswingjlabeljwindow

JWindow alway on top not getting focus events


I have a jwindow(set to be always on top) that you can click to get a pop menu. If the user right clicks the window it shows the pop menu but then if the user clicks any other window(such as firefox) pop menu does not disappear.

I tried to fix it by adding FocusListener on the jwindow, i implemented FocusListener and override


    public void focusGained(FocusEvent e) {
    System.out.println("gain" );
    }

    public void focusLost(FocusEvent e) {
    System.out.println("lost" );
    }

but there event never get called. i also tried the following,


    addWindowFocusListener(new WindowAdapter() {
        public void windowGainedFocus(WindowEvent e) {
            System.out.println("gain 2" );
        }
        });

this event also not called.

All this jwindows has is a single JLabel with a picture on it.


Solution

  • From memory JWindow's do not receive focus/window events.