Reputation: 4810
I'm using eclipse and scene builder.
I want to add elemnts on run time to tabs. Each element is fxml file (which contains button, tableView, textbox...).
The Tab will not contain fix number of elements.
I need yours help, because I cant find a way how to do it ? How can I add any eleemnt to tab ? How can I add the decribed elements (fxml) into the tab ?
Thanks
Upvotes: 1
Views: 958
Reputation: 38122
I'm not sure I'm understanding your use case completely, but have a look at the fx:root construct:
import java.io.IOException;
import javafx.scene.layout.BorderPane;
import org.drombler.commons.fx.fxml.FXMLLoaders;
public class MyCustomtPane extends BorderPane {
public TopTestPane() throws IOException {
loadFXML();
}
private void loadFXML() throws IOException {
FXMLLoaders.loadRoot(this);
}
}
In the same package add a MyCustomtPane.fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<fx:root type="BorderPane" xmlns:fx="http://javafx.com/fxml">
<center>
<Label text="%label.text"/>
</center>
</fx:root>
In the same package add a MyCustomtPane.properties file:
label.text=Some text
Somewhere else in your code you can use:
...
MyCustomtPane myCustomtPane = new MyCustomtPane(); // will load the FXML as well
addToProperPlace(myCustomtPane);
Note: FXMLLoaders is a utility class I've written. The library is Open Source and available directly from Maven Central:
<dependency>
<groupId>org.drombler.commons</groupId>
<artifactId>drombler-commons-fx-core</artifactId>
<version>0.4</version>
</dependency>
Upvotes: 1