1

I am trying to open up another app on top of one that is already open. In other words, I have the initial app that does stuff, and I have a button on the window that, when clicked, should open up another window with performance and memory statistics.

Now is the part where I'm not sure exactly what to do. I have a listener to examine when the button is clicked, but how do I get it to load another FXML class (app?).

Both app classes are in different packages as well.

G Boggs
  • 381
  • 1
  • 6
  • 19
  • 2
    Same way as you load the first FXML; just create an `FXMLLoader` and call its `load()` method. Try it and if it doesn't work, update your question to show your code and explain what goes wrong. – James_D Sep 30 '14 at 01:03

1 Answers1

0

I do something like this to load multiple FXML files in an accordian window, the process is the same for a single one, except you attach it to a new 'stage' instead of using the .setContent() method of a TitledPane (any variables I have that start with tp_ are TitledPanes):

    tp_edit_perm.setContent(FXMLLoader.load(getClass().getResource("fxml/edit_window.fxml")));
    tp_report_pane.setContent(FXMLLoader.load(getClass().getResource("fxml/report_window.fxml")));
    tp_manual_pane.setContent(FXMLLoader.load(getClass().getResource("fxml/manual_license_window.fxml")));

yours would be something like:

        Stage new_stage = new Stage();
        Parent root;
        root = FXMLLoader.load(getClass().getResource("fxml/some_fxml.fxml"));

        Scene scene = new Scene(root);

        new_stage.setScene(scene);


        new_stage.show();   

you would just do that in the button listener and switch 'fxml/some_fxml.fxml' for wherever/whatever your fxml is called.

WillBD
  • 1,919
  • 1
  • 18
  • 26