JavaFX: how to let one FXML include another

How to let one fxml include another, e.g. let every scene has a "header" ?

 

  

Note you have to set "fx:id=…"

There must be a controller for the included fxml file. Let’s call it HeaderController

   

	


  
public class HeaderController {


	@FXML
	private Text errorText;
	... 
  

Include the HeaderController in your controller

 public class LoginController {
	//the variable has to start with "header", because during the fxml inclusion you have set its id as "header", i.e., fx:id="header" 
	@FXML
	private HeaderController headerController; 
	...
	public void someMethod(){
		headerController.setErrorText("Something is wrong");        
	...  

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.