I\'m using Netbeans 7.2 with Scene Builder 1.0 to develop a JavaFX application. I have my main screen set up, and I want to have it so I click a button and it\'ll close the main
You can do it this way too:
Modify your controller.java this way
Stage thisStage;
public void setStage (Stage stage){
thisStage = stage;
}
public void showStage(){
thisStage.setTitle("Titel in der MainController.java geändert");
thisStage.show();
}
It is important that you don't use thisStage in the initialize method.
Modify your Mainclass this way:
@Override
public void start(Stage stage) throws Exception {
URL location = getClass().getResource("Main.fxml");
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(location);
fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
Parent root = (Parent) fxmlLoader.load(location.openStream());
Scene scene = new Scene(root);
stage.setScene(scene);
MainController mainController = fxmlLoader.getController();
mainController.setStage(stage);
mainController.showStage();
}
You can download a example projekt (netbeans) here.