开发者

How to keep mainframe behind dialog when switching top-level windows?

Following situation:

I have a JFram开发者_运维问答e and call JOptionPane.showInputDialog("test"). The modal dialog will be shown.

When I then switch to another open window in Windows (let's say Firefox) and then return to my Java application (by clicking the tab in the windows task bar or with ALT+TAB) then only the dialog will be shown.

Is it possible to show the main frame behind the dialog when switching to my app? E.g. Eclipse behaves the desired way when you open the Preferences dialog. Eclipse is SWT, but maybe it's possible in Swing too!


I don't know of a way to do this with JOptionPane's static methods, since you don't have access to the dialog itself. However, you can probably achieve the same thing by making your own dialog and adding a listener like this:

    final JDialog dialog = new JDialog();
    dialog.setTitle("Test Input");
    dialog.setModal(true);


    dialog.addWindowFocusListener(new WindowFocusListener() {

        @Override
        public void windowLostFocus(WindowEvent arg0) {

        }

        @Override
        public void windowGainedFocus(WindowEvent arg0) {
            frame.toFront();        
        }
    });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜