Both ScrollPane and TitledPane have Control as their base class (not counting LabeledXXX)
Both of them have content property that allows us to put a single Node inside these containers.
I have built a similar control and also added a content property. For some reasons I cannot drop any other controls like TextField on my custom control in SceneBuilder.
PROBLEM: SceneBuilder has hardcoded behaviour for certain types of build-in custom controls. This makes it unusable when you want to use a custom control or use controls from project like controlsfx.
I actually managed to make it work, adding a few changes to the code (jfx-13 branch) - see the attached patch.
The problem is that content property is not properly detected by MetadataIntrospector.
So far my PoC solution just hardcodes contents string as property name. I think it would be the best if SceneBuilder publised a small maven package with few annotations like @ContentProperty or @ChildrenProperty so that I can stick them on my custom controls properties and SceneBuilder can then figure out that the control is a kind of container.
My custom control code:
package pl.marcinchwedczuk.javafx.validation.extra;
import javafx.beans.DefaultProperty;
import javafx.beans.InvalidationListener;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.AccessibleAttribute;
import javafx.scene.AccessibleRole;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Skin;
import pl.marcinchwedczuk.javafx.validation.lib.Input;
import pl.marcinchwedczuk.javafx.validation.lib.Objection;
@DefaultProperty("content")
public class ValidationDecorator2 extends Control {
private final SimpleListProperty<Objection> objectionsProperty =
new SimpleListProperty<>(this, "objections", FXCollections.observableArrayList());
private ObjectProperty<Node> contentProperty =
new SimpleObjectProperty<Node>(this, "content", null);
public ValidationDecorator2() {
this.setPrefHeight(USE_COMPUTED_SIZE);
this.setPrefWidth(USE_COMPUTED_SIZE);
}
@Override
protected Skin<?> createDefaultSkin() {
return new ValidationDecoratorSkin(this);
}
public final ObjectProperty<Node> contentProperty() {
return contentProperty;
}
public final void setContent(Node value) {
contentProperty().set(value);
}
public final Node getContent() {
return contentProperty().get();
}
public SimpleListProperty<Objection> objectionsProperty() {
return objectionsProperty;
}
public ObservableList<Objection> getObjections() {
return objectionsProperty.get();
}
public void setObjections(ObservableList<Objection> objections) {
objectionsProperty.set(objections);
}
public <UIV,MV> void displayErrorsFor(Input<UIV, MV> input) {
this.objectionsProperty().bind(input.objectionsProperty());
}
}
Bump. It would be a really nice addition. I think simply supporting comma-separated values list in the @DefaultProperty would be much easier than publishing another Maven artifact.
ScrollPane
andTitledPane
haveControl
as their base class (not countingLabeledXXX
)content
property that allows us to put a singleNode
inside these containers.content
property. For some reasons I cannot drop any other controls likeTextField
on my custom control in SceneBuilder.PROBLEM: SceneBuilder has hardcoded behaviour for certain types of build-in custom controls. This makes it unusable when you want to use a custom control or use controls from project like controlsfx.
I actually managed to make it work, adding a few changes to the code (jfx-13 branch) - see the attached patch. The problem is that
content
property is not properly detected byMetadataIntrospector
.So far my PoC solution just hardcodes
contents
string as property name. I think it would be the best if SceneBuilder publised a small maven package with few annotations like@ContentProperty
or@ChildrenProperty
so that I can stick them on my custom controls properties and SceneBuilder can then figure out that the control is a kind of container.My custom control code:
And Skin for the above:
Git Patch of PoC: