【发布时间】:2016-06-27 19:56:27
【问题描述】:
我已经为两个窗口/阶段编写了一个控制器。 第一个窗口在 MainClass 中打开。控制器中的第二个,如果用户单击一个按钮。 如何在 applyFor() 方法中从 second.fxml 获取 TextFields?
谢谢。
@FXML
protected void requestNewAccount(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("second.fxml")); // TextFields in there
Parent root = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.setTitle("Second Window");
Scene scene = new Scene(root);
String css = MainOnlineCustomer.class.getResource("/style.css").toExternalForm();
scene.getStylesheets().clear();
scene.getStylesheets().add(css);
stage.setScene(scene);
stage.show();
} catch (IOException e) {
logger.error(e);
}
}
/**
* closes the "second"-Window
* @param event
*/
@FXML
protected void cancel(ActionEvent event) {
final Node source = (Node) event.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
@FXML
protected void applyFor(ActionEvent event) {
// get values from TextField in second.fxml here!!!
}
【问题讨论】:
-
将操作按钮绑定到applyFor方法,并从second.fxml为TextField设置一个Id。