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

192 views Asked by At

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!

2

There are 2 answers

0
Sergiy Medvynskyy On BEST ANSWER

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.

0
camickr On

what listener should i use to trigger when the JPopupMenu becomes visible!

In case you want the code to execute before the menu is visible so you can configure the popup you can add a PopupMenuListener to the JPopup. It supports 3 events:

  1. popupMenuCanceled
  2. popupMenuWillBecomeInvisible
  3. popupMenuWillBecomeVisible