JavaFX阶段模式 [英] JavaFX Stage Modality
问题描述
我试图制作一个通过舞台打开的Modal窗口.这是代码:
I am trying to make a Modal window, opened through a Stage. This is the code:
Stage stage = new Stage();
Parent root = fxmlLoader.load();
stage.setScene(new Scene(root));
stage.setTitle("Stuff");
stage.initModality(Modality.WINDOW_MODAL);
stage.show();
但是,按我的方式,单击下面的窗口并没有实际成功. 我有做错什么吗?
But with no actual success, as I am able though, to click the underlying windows. Is there anything that I am doing wrong?
我在Oracle站点上查阅了早期文档,但是可以找到解决方案,因为显示的窗口的行为与模态窗口"的预期行为并不太相像. 我在该项目上使用的JDK是1.8.0_40
I checked earlier the documentation at Oracle's site, but could find a solution, as the displayed window's behavior wasn't any close to what its expected from a Modal Window. The JDK I am using on this project is 1.8.0_40
根据ItachiUchiha的要求,句柄中的代码
EDIT 2: The code within the handle, as requested by ItachiUchiha
Boolean confirmacion = MessageUtil.ventanaConfirmacion(RecursosUtil.creaTextoProperties("confNoRealizar"));
if (confirmacion) {
try {
TbInspeccion inspeccionSeleccionada = (TbInspeccion) getTableRow().getItem();
URL location = cargaURLFXML(OBSERVACIONESFXML);
FXMLLoader fxmlLoader = cargaFXML(location);
stage = new Stage();
Parent root = fxmlLoader.load();
stage.setScene(new Scene(root));
stage.setTitle("Observaciones");
ObservacionesController controller = (ObservacionesController) fxmlLoader.getController();
controller.setStage(stage);
controller.setInspeccion(inspeccionSeleccionada);
controller.setProvider(provider);
controller.setTablaPrincipal(tablaPrincipal);
stage.initModality(Modality.APPLICATION_MODAL);
stage.show();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
感谢您的时间和帮助.
推荐答案
替换
stage.initModality(Modality.WINDOW_MODAL);
与
stage.initModality(Modality.APPLICATION_MODAL);
前者阻止如下:
定义一个模式窗口,该窗口阻止事件传递给它 整个所有者窗口层次结构.
Defines a modal window that block events from being delivered to its entire owner window hierarchy.
而后者:
定义一个模式窗口,该窗口阻止事件传递给任何事件 其他应用程序窗口.
Defines a modal window that blocks events from being delivered to any other application window.
来源: https://docs.oracle. com/javase/8/javafx/api/javafx/stage/Modality.html
Depending on why you want to achieve the aforementioned behaviour you might want to use JavaFX 8 Dialog available from JDK 8 Update 40
这篇关于JavaFX阶段模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!