我有一个Swing应用程序,其主窗口继承了JFrame
类。这个应用程序正在转换到JavaFX,所以JavaFX组件包括控制面板有很多。
我需要以相对于主JFrame
的模态方式从非UI线程显示本机文件选择器。
这可以通过设置FileChooser
类的所有者来实现,但需要javafx.stage.Window
作为所有者。
是否存在将JFrame
设为javafx FileChooser
或Stage
的所有者的行为?
答案 0 :(得分:2)
解决方案可能是在JFrame
关闭之前禁止以某种方式选择FileChooser
。
这是一些伪代码,因为我不知道那么好摆动:
setFocusableWindowState(false)
?)Thread.join()
完成或者您想管理线程),将焦点恢复到JFrame 答案 1 :(得分:1)
实际上就像是:
JFrame frame = // get window
frame.setEnabled(false); // emulate window modality
File file = fileChooser.showOpenDialog(null);
if (file == null || !openFile(file)) { // return true if file was opened correctly
frame.setEnabled(true);
frame.requestFocus(); // window looses focus after enabling
}
所以FileChooser
的行为就像模态窗口一样。缺点是需要控制所有路径以启用窗口,因此它不会永远保持禁用状态。