Javafx popup won't hide behind other application upon losing focus

末鹿安然 提交于 2019-12-05 11:06:31

So, after toying with this for a few more days, I have a rough workaround, although it is a hack in the full meaning of the term.

Although the popup behaviour is still mystifying me, I can simulate a fix in this behaviour by adding a changeListener to the stage to which it is attached (since I didn't want the popup to close if it's parent window had focus, only if anything BUT the popup and it's parent got focus).

See code as follows:

FileChooserWindow.get_stage().focusedProperty().addListener(new ChangeListener<Boolean>(){
            @Override
            public void changed(ObservableValue<? extends Boolean> ov, Boolean oldValue, Boolean newValue) {
                if (!newValue){
                    if(AutogenPopup.popupReturner().focusedProperty().get()){
                        AutogenPopup.popupReturner().hide();
                    }
                }else{
                    if(FileChooserController.refreshAutoPopup && FileChooserController.autoGen_flag){
                        AutogenPopup.popupReturner().show(FileChooserWindow.get_stage());
                    }
                }
            }

        });

never mind some of those flags that I'm checking against, they are simply some internal tools to make sure that the popup only appears when the program is in the proper state.

Now, one interesting thing to note. The AutogenPopup.popupReturner().focusedProperty().get() Seemed to be returning true when the popup's parent window LOST focus. Which is quite counter-intuitive to me, and in my opinion, is even a touch buggy. Now, this does not simulate the behaviour of a modern operating system where a window can slide in and out of focus incrementally, since the popup will just completely disappear upon it's parent window losing focus. But seeing as how my popup just displays additional text entry on the side of the main window, this is an acceptable compromise until I think of a better solution. (Perhaps the better solution is not to use a popup at all, and instead skin a window to act in a popup-y fashion).

Anyway, I hope this helps someone, maybe eventually there will be a more fine-grained way to control this popup functionality.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!