作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚来自Is There any Way to Create A Child Window That Has the Same Properties as the Parent?我尝试调用stage.initOwner(((Node) event.getSource()).getScene().getWindow());
但它不起作用,我得到了一个异常(exception)。我认为我没有正确使用它。我应该如何尝试从 onAction 方法调用它?
原始代码块:
@FXML
private void onNewClanCreation(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("ClanCreationPanel.fxml"));
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.initOwner(((Node) event.getSource()).getScene().getWindow());
stage.setResizable(false);
stage.setTitle("New Clan Creation");
stage.show();
}
异常(exception):
`Caused by: java.lang.ClassCastException: javafx.scene.control.MenuItem cannot be cast to javafx.scene.Node at com.gmail.physicistsarah.program.core.ControlPanelController.onNewClanCreation(ControlPanelController.java:65)
... 54 more`
编辑:添加了 stage.initOwner
最佳答案
这有效:stage.initOwner(this.nameLabel.getScene().getWindow());
谢谢@ItachiUchiha
关于java - 如何从 MenuItem On Action 方法调用 Stage.initOwner()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23851845/
我是一名优秀的程序员,十分优秀!