0

Is it possible to add a controller to a Scene? such that it has the same effect as adding the loaded Nodes from the FXML? What I am currently doing to load my FXML is this:

fxmlLoader = new FXMLLoader(getClass().getResource("fxml"));
Parent page = null;
page = fxmlLoader.load();

And I am able to attach the Parent to the scene. But if , instead, I attach the controller that I get with this code (just below the previous code):

controller = fxmlLoader.getController();

Then attaching this controller to my scene does not do anything, nothing shows.

Jupiter
  • 91
  • 1
  • 1
  • 7
  • 2
    A controller is not a graphical component. It processes the logic associated with a set of graphical components (e.g. initialization and processing user input). What do you expect to see if you "add the controller to the scene" - there's no sense of what it even looks like. Also, what code are you using to add the controller to the scene? I don't think anything like that would compile. – James_D Oct 29 '14 at 22:09
  • A controller can be cast as a Node, and there is no compile error when you attach it as a child of a component, like this: panel.getChildren().add(controller); – Jupiter Oct 30 '14 at 14:39
  • Yes, ok, but your controller is not a node (or certainly shouldn't be), so it would fail at runtime. Maybe you need to edit your question with a short example to show what you are doing. – James_D Oct 30 '14 at 14:41

0 Answers0