0

So here is the problem I am having: I have 3 button, when I press one of the 3 buttons the new scene will display. Yet I cant seem to figure out how to make different panes appear visible depending on which button is pressed. what is the best method to perform this action? How do i use Id's from different scene controllers in order to change the properties of the pane within the main scene button listener?

currently on my main controller when each button is released the below action listener executes and displays secondscreen.fxml. the secondscreen.fxml has 2 different panes, depending on which button is pressed I need 1 of the 2 pains to set to visable.

@FXML
 public void handleButtonAction(MouseEvent event) {
    Parent root;
    try {
        root = FXMLLoader.load(getClass().getResource("secondscreen.fxml"));
        Stage stage = new Stage();
        stage.setTitle("title");
        stage.setScene(new Scene(root));
        stage.show();

        ((Node)(event.getSource())).getScene().getWindow();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
B.Thompson
  • 27
  • 7
  • Other than suggesting you use a [`TabPane`](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TabPane.html) for this kind of functionality, can you post some code to give an idea of what you already have? Otherwise there are just too many ways to do this, and the question is really too broad. – James_D Mar 08 '16 at 02:27
  • James does my edit help clarify what I'm trying to accomplish. A tab pane is not a option. – B.Thompson Mar 08 '16 at 03:01

1 Answers1

0

After you load a view, you can access its controler.

Keep in mind, that your controller must be asigned to your fxml file fx:controller="your.package.SecondScreenController.java"

FXMLLoader loader = new FXMLLoader.load(getClass().getResource("secondscreen.fxml"));
// load view
Parent root = loader.load();
// after view is loaded, access its controller
SecondScreenController controller = (SecondScreenController) loader.getController();
// modify view using methods on your controller
controller.setTabIndex(0)

Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.show();
Jan Lochman
  • 439
  • 3
  • 12