I have 2 fxml files:
- Layout (header, menubars and content)
- Anchorpane (it's supposed to be placed inside the content from the other fxml file)
I would like to know how can I load the second file inside the content space from the "Master" scene. And is that a good thing to do working in javaFX or is it better to load a new scene?
I'm trying to do something like this, but it doesn't work:
@FXML
private AnchorPane content;
@FXML
private void handleButtonAction(ActionEvent event) {
content = (AnchorPane) FXMLLoader.load("vista2.fxml");
}
Thanks for the help.
In this case, I recommend you to use custom component instead. First create a custom component for your content:
Replace the
AnchorPane
markup in the root of yourvista2.fxml
file withfx:root
:Then, you can do this simply by using custom event binding and arrow function. Add event handler property to your
Content
class:Finally, bind your custom event handler in your java code or fxml:
If you don't want to add content dynamically, just
setVisible()
totrue
orfalse