问题
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