'JavaFX - How to get custom properties in scene builder?

I am looking for a solution to define editable properties of custom controls. Jens Deters built already superb custom controls with fontawesomefx for JavaFX.

After the import of the jar-files into Scene Builder you are able to use custom controls (drag & drop). The best thing is that you are able to style the symbols directly in the properties menu. You are able to style special node properties on the fly.

My question is, how it is possible to create editable custom (node) properties directly in the properties menu of Scene Builder? Is there a workflow?



Solution 1:[1]

Once you have added your custom component, if you click on it, the right panel containing the section Properties, Layout and Code are updated. In the Properties section, there is on the top a Custom subsection which contains your custom properties, in the following example I added Error Text, Field Type and Title text: enter image description here

To add these custom properties, you have to add them as attributes in the custom component controller:

private ObjectProperty<FieldType> fieldType = new SimpleObjectProperty<>(FieldType.NONE);
private StringProperty titleText = new SimpleStringProperty();
private StringProperty errorText = new SimpleStringProperty();

These attributes shall be properties, no @FXML is needed, if you enter a value, for example NONE for the enum, then it will be set as default value in the scene builder custom property

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Skartt