开发者

How to show popup on other popup?

开发者 https://www.devze.com 2023-02-18 06:10 出处:网络
In my application, on some screen, I launch a popup. Depends on what button the user will click on th开发者_Go百科is popup, another popup has to be launched. I use JDialog object to implement these po

In my application, on some screen, I launch a popup. Depends on what button the user will click on th开发者_Go百科is popup, another popup has to be launched. I use JDialog object to implement these popups. The issue is that the second popup doesn't show up (even though is use setVisible(true) and toFront()). It's created but I can't see it. I defined in its constructor the first popup as its owner. Anyone can help?


When a JDialog is opened from a parent window or dialog, and set to be modal, the Event Dispatch Thread for the parent window is halted. This prevents the parent from being focused or from passing other events, or essentially doing anything until the modal dialog is closed. The call is therefore blocking.

What you must do instead is fire your event from somewhere else, like the new dialog instead of the parent window, OR instead of using modal dialogs, use a regular JFrame and set it to be always on top using setAlwaysOnTop(true). That means the user can continue to use the parent window, and events will still fire from it.

Addendum: in response to your problem "the program concentrates in showing it and doesn't react to the event that has to hide it": when you make a dialog modal, as soon as you make it visible, it will block the parent window until it is closed, including event firing. If you need the new popup to be closed programatically, you either need to make the popup non-modal, or you need to execute the subsequent code in the context of the new popup window (such as firing an event when it becomes visible)


OK, now I managed to show the second popup. The code in the event that triggers the popup is:

printingWindow.setLocationRelativeTo(null);
printingWindow.toFront();
printingWindow.setModal(true);
printingWindow.pack();
printingWindow.setVisible(true);

But now I have a different problem:

when the printingWindow is set to be visible, the program concentrates in showing it and doesn't react to the event that has to hide it.

The code that is executed when the appropriate event is fired is:

printingWindow.setVisible(false);
printingWindow.dispose();

So how I close this popup (by firing the event)?

0

精彩评论

暂无评论...
验证码 换一张
取 消