views:

297

answers:

3

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.

A: 

Not really sure what you are trying to do. If you are trying to hide the popup manually then you should probably use a WindowListener and handle the windowDeactivated event.

camickr
i don't want to deactivate popup manually i am doing it because swing doesn't do it. just as a workaround.
Hamza Yerlikaya
A: 

If you really want to display a popup menu, you should be using JPopupMenu, not implementing it yourself.

Software Monkey
+1  A: 

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

objects
yep thats the case switched to JFrame set it to undecorated solved my problem.
Hamza Yerlikaya