Notification of JPopupMenu dismissal

W

Will Barker

I am currently using the following to display a popup menu :

JPopupMenu popup;
..
..
popup = new JPopupMenu();
menuItem = new JMenuItem("test...");
menuItem.addMouseListener( new MyMouseListener() {

public void mouseReleased(MouseEvent m) {
} // MouseReleased
});
..
..
popup.add(menuItem);
..
..
popup.show(e.getComponent(),e.getX(),e.getY());

When the user then clicks on the test menuitem, mouseReleased gets called.
That's fine. But what if the user dismisses the menu e.g. by clicking
outside the area of popup. How do I get notification of that? Is there some
event I can look out for?
 
T

Thomas Weidenfeller

Will said:
When the user then clicks on the test menuitem, mouseReleased gets called.
That's fine. But what if the user dismisses the menu e.g. by clicking
outside the area of popup. How do I get notification of that? Is there some
event I can look out for?

JPopupMenu is supposed to handle all this internally. Do not define any
mouse handlers or other listeners. Just provide the correct invoker in
the show() method.

BTW: Comp.lang.java.gui is next door.

/Thomas
 
B

Babu Kalakrishnan

Will said:
I am currently using the following to display a popup menu :

JPopupMenu popup;
.
.
popup = new JPopupMenu();
menuItem = new JMenuItem("test...");
menuItem.addMouseListener( new MyMouseListener() {

public void mouseReleased(MouseEvent m) {
} // MouseReleased
});
.
.
popup.add(menuItem);
.
.
popup.show(e.getComponent(),e.getX(),e.getY());

When the user then clicks on the test menuitem, mouseReleased gets called.
That's fine. But what if the user dismisses the menu e.g. by clicking
outside the area of popup. How do I get notification of that? Is there some
event I can look out for?

popup.addPopupMenuListener(yourPopupMenuListener);

And look at the methods in the PopupMenuListener interface

BK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top