Search code examples
javaswinglistenerjpopupmenu

Java - Triggering a JPopupMenu to execute code when it is shown?


When a JPopupMenu appears i want to execute some code for it. I can't figure out what listener should i use to trigger when the JPopupMenu becomes visible!


Solution

  • You should register a property change listener.

    JPopupMenu menu = new JPopupMenu();
    menu.addPropertyChangeListener("visible", myPropertyChangeListener);
    

    In the listener you should check whether the new value of the event is Boolean.TRUE.