0

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.

user629926
  • 1,910
  • 2
  • 18
  • 43

3 Answers3

3

Take a look at How to use Dialogs

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

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
1

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

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

Rob I
  • 5,627
  • 2
  • 21
  • 28
  • That's ok ,but I want to "block" current thread w/o bocking the whole ui until popup menu closes. – user629926 Apr 11 '13 at 20:04
  • use JOptionPane (block code execution by default) instead of JPopup, put there JButtons instead of JMenuItems, sure is possible to put JMenuItems to JPanel, but why bothering – mKorbel Apr 11 '13 at 20:08
  • Then I think @MadProgrammer's answer will get you where you want to go. I got hung up hearing "popup menu", but I suspect you can do everything you need to with a dialog. – Rob I Apr 11 '13 at 21:25
0

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
    }
});
MHeads
  • 267
  • 1
  • 7
  • 18