开发者

removing focus from JDialog if main application is minimised

I have a JDialog which popup whenever my main application recieves an event. The problem I'm facing is that the dialog pops up evenif the main window is minimised. A similar question was asked here but no answer was given as to how to solve this except a link to sun's guide on focus handling Hide JDialog window when the window lost focus.

Suppose I have the function createandshowDialog() such as

public void createAndShowDialog(boolean manualLaunch) {
        if (manualLaunch || shouldShowMessage()) {
            SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {                        
                        if (dialog == null) {
                            dialog = new xyzDialog(getPendingList());
                        }
                        GUIHelper.flash(PLAFHelper.getMainFrame(), true, false);
                        dialog.setVisible(true);
                   }
                });
            }
}

And the xyzDialog class is defined as :

  public class xyzDialog extends SimpleStandardDialog
  {
    protected final static Log logger = LogFactory.getLog(xyzDialog.class);

    private xyzPanel panel;

   public xyzDialog(ObjectArrayList list) {
        super(PLAFHelper.getMainFrame(), "Pending Cancel/Replace");
        initializeLocalVars();
        panel = new xyzPanel(list, mediator);
        super.setSize(750,600);
        setResizable(true);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        setModal(false);//todo: for testing...

        if(PUMAGUIOptions.cFocusOnxyzPopup){
            setFocusableWindowState(true);
            validate()开发者_StackOverflow社区;
        }
        else{
            setFocusableWindowState(false);
            validate();

        }

    }

The default behaviour should be such that it should not popup if main window is minimised or we explicitly set cFocusOnxyzPopup as false to force this default behaviour (which is the case when it is open on say secondary monitor and we are working on primary monitor or application is maximised or is in background i.e. is not the focusOwner.

I have set focusableWindowState as false so that it would not satisy the condition for gaining focus and return isFocusable as false if invoked as given in java-docs. But this is not working. Any suggestions?


USe JFrame's method

public synchronized int getExtendedState()

e.g. PLAFHelper.getMainFrame().getExtendedState()

if it's JFrame.ICONIFIED skip the dialog opening.


I have meet the same problem and search the stackoverflow ! finally, I find out the

corrent answer answered by Markus Lausberg in JDialog lets main application lose focus

just calling the following method during dialog create:

setFocusableWindowState(false); setFocusable(false);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜