r/JavaFX • • Jun 18 '24

Help Need some help integrating custom control props (Not the usual props types) in SceneBuilder

I'm developing a new Java-fx custom control that will facilitate responsive UI design by having size breakpoints , similar to bootstrap or any other web css lib for responsive design. My question is :

How can I archive the same as the AnchorPane does with the static methods setTopAnchor, setLeftAnchor, etc, the constraints , and be able to load that in SceneBuilder in order to set the values for each Node inside it. My control have a similar approach to set properties for each child node independently, like col-span, col-offset, etc, but I'm unable to get that to work in SceneBuilder. The only way I was able to do that was by creating a Node Wrapper and declaring the properties inside that class, but that means adding another Node extra for each child and I don't wan that . If you guys use a specific way to do that and can point me in the right direction I will appreciate it . Thanks

Example of custom Node props:

/**
 * Column count for extra small screens.
 */
private static final String EXTRA_SMALL_COLS = "xs-cols";

/**
 * Sets the column span for extra small screens.
 *
 * u/param node The node to set the column span on.
 * u/param value The column span value.
 */
public static void setXsColSpan(Node node, Double value) {
    setConstraint(node, EXTRA_SMALL_COLS, value);
}

/**
 * Retrieves the column span for extra small screens.
 *
 * @param node The node to get the column span from.
 * @return The column span value.
 */
public static Integer getXsColSpan(Node node) {
    return (Integer) getConstraint(node, EXTRA_SMALL_COLS);
}

Example in manually written fxml :

Example in manually written fxml

Result :

Its fully responsive and works like a charm, Im just unable to set those properties from SceneBuilder. If someone has a hint on that , pls share.

1 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/xdsswar Jun 19 '24

This is different. I'm working on a real demo to post. This is a completely new kind of layout, something where you can make anything you place inside it responsive by setting specific properties I created for this purpose. I know this is achievable using reflection; I just need to understand the SceneBuilder codebase better. Besides, FlowPane will not do the job as it leaves unused space on resize unless you override layoutChildren and set your own rules.

All I did is based on the Bootstrap responsive layout principles, using breakpoints, similar to media queries (not CSS). You can set colSpan and colOffset for each node inside my layout, independently for each breakpoint, so your UI will be 100% responsive. I tested it, and it works like a charm. As you mentioned, SceneBuilder sucks, but you know, I will share this, and some people feel okay using SceneBuilder. That’s why I want to find a way for it to work, similar to how AnchorPane does with its nodes. The library can be imported into SceneBuilder; you just need to set the custom properties manually for each node.

1

u/hamsterrage1 Jun 19 '24

Isn't there a List inside Node called "properties"? I wonder if it's there to support SceneBuilder.

1

u/xdsswar Jun 19 '24

There is a map , thats what Im using, Im uploading a demo to ahow you, in few mins