To create a custom control that Scene Builder can recognize and manipulate in the Inspector, implement a standard JavaFX Control with a custom Skin.
FXML Annotations for Custom Controls
Use these annotations to ensure your control works seamlessly with FXMLLoader:
@DefaultProperty: Specifies a property that child elements are added to or set when no explicit property is provided.@NamedArg: Allows FXMLLoader to instantiate a class that lacks a zero-argument constructor by mapping FXML attributes to constructor parameters.
A complete implementation includes the Control class, the Skin class, and a CSS file for styling. Once added to Scene Builder, the control's properties appear in the Inspector area for user interaction.
package popup;
import javafx.beans.NamedArg;
import javafx.beans.DefaultProperty;
import javafx.scene.control.Control;
@DefaultProperty("content")
public class Popup extends Control {
// Use @NamedArg to allow instantiation without a no-arg constructor
public Popup(@NamedArg("message") String message) {
setContent(message);
}
// Standard JavaFX property pattern
private final StringProperty content = new SimpleStringProperty(this, "content", "Default Message");
public final String getContent() { return content.get(); }
public final void setContent(String value) { content.set(value); }
public final StringProperty contentProperty() { return content; }
@Override
protected Skin<?> createDefaultSkin() {
return new PopupSkin(this);
}
}