-1

I am using Scene Builder to create a JavaFX GUI application. I am trying to implement something like this, using FXML:

reportButton = new Button("Report");
reportButton.setOnAction(e -> ReportPage.display());

but I can't figure it out how to do that using the controller page. Can someone please tell me how do I do that? Thank you

ToniT
  • 102
  • 8
  • Please post more code and the fxml file(s)… It really depends on how you have implemented the different views. Do they have a common parent view? – deHaar Oct 19 '17 at 13:28
  • Just define the appropriate method in the controller. See the [documentation](https://docs.oracle.com/javase/9/docs/api/javafx/fxml/doc-files/introduction_to_fxml.html#controller_method_event_handlers). – James_D Oct 19 '17 at 14:01
  • Are you trying to open a new stage? Change the current scene? Place the view in a container on the current stage? – purring pigeon Oct 19 '17 at 14:15
  • Use google before asking – Developer66 Oct 19 '17 at 14:44

1 Answers1

2

Here is how could show a new stage. Add this code in your on action function
(you can add that function with scene builder in code : On action property)

@FXML
private void reportButtonHandler(ActionEvent event) {
    FXMLLoader fxmlLoader = new 
        FXMLLoader(getClass().getResource("pathtofxml/ReportPage.fxml"));
    Parent root1 = (Parent) fxmlLoader.load();
    Stage stage = new Stage();
    //set what you want on your stage
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setTitle("Report Page");
    stage.setScene(new Scene(root1));
    stage.setResizable(false);
    stage.show();
}
DeadPool
  • 42
  • 1
  • 10