How to show java FileDialog in Front of Google Dev Tools (AlwaysOnTop does not work)

大憨熊 提交于 2019-12-08 13:44:31

问题


I try to use following Java method to open a file selection dialog on top of all other windows (Windows7, Java 11).

However, the dialog is shown behind my Google Chrome Dev tools.

protected String result(String initialDirectory)  {         

        var fileDialog = new FileDialog(getFrame(), "Choose a file", FileDialog.LOAD);
        fileDialog.setIconImage(getDialogIcon());

        if (initialDirectory!=null) {
            fileDialog.setDirectory(initialDirectory);
        }

        fileDialog.setFocusable(true);          
        fileDialog.setLocationByPlatform(true);
        fileDialog.setVisible(true);    
        fileDialog.setAlwaysOnTop(true);
        fileDialog.toFront();
        fileDialog.repaint();

        var file = fileDialog.getFile();
        if(file != null) {
            var directory = fileDialog.getDirectory();
            var path =  directory + file;
            return path.replace("\\", "/");
        } else {
            return "";
        }           
    }   

=> How can I ensure, that the file selection dialog is really shown on top of all other windows? Do I need to somehow monitor all windows and adapt some priority or so?

Related question:

"Always on Top" Windows with Java

来源:https://stackoverflow.com/questions/58371767/how-to-show-java-filedialog-in-front-of-google-dev-tools-alwaysontop-does-not-w

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