Intro:
Hi, I've been having trouble with FXML, and it's driving me mad.
Background Story:
I have build a tree data structure in Java, this tree represents the "state" of my GUI (Human interface). For every node of this tree i would like to have a corresponding FXML file, of which the name is stored within the tree nodes. My hope is to open the root node (special nodes in the tree), and embed multiple loose FXML files into it, depending on the current Tree state.
Problems:
I don't know how to pass variables from the application to the FXML
I don't know how to Instantize an FXML with
fx:include, send it some string parameters with links (to other FXML), and create a flexible app.
What I have tried
Everything that looked remotely like a solution up to google page 4, (duckduckgo page 2). I haven't been able to try a lot, because apparently nobody ever wanted to load in variables/fxml pages.
I've also followed the tutorial.
Application class:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXML loader = new FXMLLoader(getClass().getResource("sample.fxml"));
Map<String, Object> namespace = loader.getNamespace();
namespace.put("a", "sample2.fxml");
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(loader.load(), 300, 275);
primaryStage.show();
}
public static void main(String[] args){launch(args);}
}
FXML File with include:
<GridPane fx:controller="sample.Controller"
xmlns:fx = "http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<fx:include source = "$a"/>
</GridPane>
What happens with the given example
The FXML doesn't compile because it doesnt know "$a"