I was having issues to display a custom component in scene builder 1.1 when referencing a java fx component that also had references to another custom components from external a library.
So, rephrasing , it´s a local custom fx component that uses external (a library project) with custom fx components.
For the development of the custom fx compoment i used this tutorial. Note that i am using the componnet in the fxml and not in code.
So my custom component fxml in the main project was like this, note the first line, im importing the library with the custom component and the last line defines for the scene builder the jar with the component:
So my custom component fxml in the main project was like this, note the first line, im importing the library with the custom component and the last line defines for the scene builder the jar with the component:
- <?import external.component.*?>
- <?import java.lang.*?>
- <?import java.net.*?>
- <?import java.util.*?>
- <?import javafx.collections.*?>
- <?import javafx.scene.*?>
- <?import javafx.scene.control.*?>
- <?import javafx.scene.layout.*?>
- <?scenebuilder-classpath-element ../../../../../ExternalLibrary/dist/ExternalLibrary.jar?>
- <fx:root type="javafx.scene.layout.AnchorPane" fx:id="ancUserInfo" l>
- <external components here/>
- <fx:root/>
it´s class
- public class UserBasicInfo extends AnchorPane {
- public static final String PROP_PATH = "";
- private static final String FXML_PATH = "";
- public UserBasicInfo() {
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(FXML_PATH));
- fxmlLoader.setResources(bundle);
- fxmlLoader.setRoot(this);
- fxmlLoader.setController(this);
- try {
- fxmlLoader.load();
- } catch (IOException exception) {
- throw new RuntimeException(exception);
- }
- }
- }
Now the issue:
I want to use this local component in another fxml, within the main project. Well, in the new fxml i would just use a reference to the .jar of the main project itself and add the import tag to the classpath within the project.
- <?import mainproject.components.*?>
- <?import java.lang.*?>
- <?import java.net.*?>
- <?import java.util.*?>
- <?import javafx.scene.*?>
- <?import javafx.scene.control.*?>
- <?import javafx.scene.layout.*?>
- <?scenebuilder-classpath-element ../../../../dist/mainproject.jar?>
- <AnchorPane id="AnchorPane" >
- <UserBasicInfo />
- <AnchorPane />
Now it won´t work, the loader seems to only get the imports from the main fxml, the local component that uses external components won´t load at least not in the scene builder. So what you do?
Add to the fxml that uses the local component also referencs to the external components like this:
- <?import mainproject.components.*?>
- <?import external.component.*?>
- <?import java.lang.*?>
- <?import java.net.*?>
- <?import java.util.*?>
- <?import javafx.scene.*?>
- <?import javafx.scene.control.*?>
- <?import javafx.scene.layout.*?>
- <?scenebuilder-classpath-element ../../../../dist/mainproject.jar?>
- <?scenebuilder-classpath-element ../../../../../ExternalLibrary/dist/ExternalLibrary.jar?>
Hope it helps someone else don´t lose time as i did.
Thank you for reading.