How to wait for popup menu closing in swing

1.1k views Asked by At

I'm new to swing and I'm sure there is an another way, but due of some akward api desing I have to implememnt a handler that recives MouseEvent and return an resault. I would like to show popup menu to user and wait for it to close and return value based on what user chose. How to do that? Thanks in advance. OK specific problem: Substance TabCloseCallback imterface has the folowing method.

 public TabCloseKind onAreaClick(JTabbedPane tabbedPane,
          int tabIndex, MouseEvent mouseEvent);

I wish to show popup menu when it's called nad return value based on what user have chosen.

3

There are 3 answers

3
Rob I On

Take a look at the events you can see by calling JPopupMenu.addPopupMenuListener().

In particular, you can get a popupMenuWillBecomeInvisible() call.

0
MHeads On

you can handle the close event in your popup class and set variables to the data you expect

yourWindow.addWindowListener(new WindowAdapter() {

    @Override
    public void windowClosing(WindowEvent e) {

        // catch what you want
    }
});
0
MadProgrammer On

Take a look at How to use Dialogs

This will allow you to show a window that will block until the user closes it