JFX component from other components

How can I have custom component designed in fxml but still usable like <TestComponent />
9 Replies
JavaBot
JavaBot8mo ago
This post has been reserved for your question.
Hey @Koblížkáč! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
stechy1
stechy18mo ago
Just create a class with the name TestComponemt, extend some existing javaFX control or even a Control class and you are ready to go.
Koblížkáč
KoblížkáčOP8mo ago
yeah but how can i design its children in fxml? thats my goal i want to basically create anchor pane with toolbar n stuff it would make it easier if i could od it in fxml because ill reuse it
stechy1
stechy18mo ago
If you extend some container class like VBox you can simply put children there like you put into a VBox
Koblížkáč
KoblížkáčOP8mo ago
i think u dont understand me, i want it to work like react components if you know, you have components with predefined children, which will be there whenever u use it. i could add them in ctor, but it would be better as fxml i think
stechy1
stechy18mo ago
I don't know react. Can you show an example of the final FXML file? Maybe we will find a solution...
Koblížkáč
KoblížkáčOP8mo ago
well what i meant is that i want this fxml:
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="lol.koblizek.bytelens.core.controllers.SidePaneController"
stylesheets="@../styles/darcula.css"
prefHeight="400.0" prefWidth="600.0">
<ToolBar prefHeight="40.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Label fx:id="titleLabel" text="Undefined" />
</ToolBar>
</AnchorPane>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="lol.koblizek.bytelens.core.controllers.SidePaneController"
stylesheets="@../styles/darcula.css"
prefHeight="400.0" prefWidth="600.0">
<ToolBar prefHeight="40.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Label fx:id="titleLabel" text="Undefined" />
</ToolBar>
</AnchorPane>
to represent my TestComponent
stechy1
stechy18mo ago
You can do the following: Create a class "TestComponent" which will extend for example a StackPane. Then in the constructor you will load the fxml file you provided and set it as a child of your component. Then you just have to somehow propagate the controller of the loaded view.
JavaBot
JavaBot8mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server