例如,我想在点击按钮时打开DirectoryChooser:
<VBox fx:controller="com.foo.MyController"
xmlns:fx="http://javafx.com/fxml">
<children>
<Button text="Click Me!" onAction="#handleButtonAction"/>
</children>
</VBox>
Controller类:
package com.foo;
public class MyController {
public void handleButtonAction(ActionEvent event) {
DirectoryChooser dc = new DirectoryChooser();
File folder = dc.showDialog(null);//I want to put the WIndows here.
}
}
我想将主窗口放到 ShowDialog 中,以便它被阻止但我该如何访问它?
答案 0 :(得分:40)
您可以向任何节点询问Scene
,然后致电Scene#getWindow()
。
E.g。 ((Node)event.getTarget()).getScene().getWindow()