我的问题相对简单,我创建了一个自定义控件,我想从其中的“ SceneBuilder”中拖放“节点”。 (见下图)
public class CustomControl extends Control {}
我创建一个“ StackPane”,然后在其中添加控件,然后在其中添加另一个“ StackPane”
您可以看一下本课程,以使您了解我正在尝试做的事情。
public class SplitPane extends Control {}
或者这个:
public class TitledPane extends Labeled {}
我的场景构建器版本:8.5.0 [胶子]
我的Java版本:1.8.0_191 [Oracle]
不要忘记这是一个简单的示例
@DefaultProperty("contentProperty")
public class CrushPane extends Control {
// Fields
private ObjectProperty<Node> contentProperty = new SimpleObjectProperty<>(this, "contentProperty");
// Constructor
public CrushPane() {
this(null);
}
public CrushPane(Node content) {
setContent(content);
}
// Getters and Setters
public Node getContent() {
return contentProperty.get();
}
public ObjectProperty<Node> contentProperty() {
return contentProperty;
}
public void setContent(Node content) {
contentProperty.set(content);
}
// Override methods
@Override
protected Skin<?> createDefaultSkin() {
return new CrushPaneSkin(this);
}
}
皮
public class CrushPaneSkin extends SkinBase<CrushPane> {
//-----------------------------------------------
//Fields
private final ChangeListener<Node> contentChanged = (ob, o, n) -> onContentChanged(n);
private AnchorPane root;
//-----------------------------------------------
//Constructor
public CrushPaneSkin(CrushPane crushPane) {
super(crushPane);
this.root = new AnchorPane();
getChildren().add(this.root);
crushPane.contentProperty().addListener(contentChanged);
}
//-----------------------------------------------
//Events
private void onContentChanged(Node newValue) {
ObservableList<Node> children = root.getChildren();
children.clear();
if (newValue != null) {
children.add(newValue);
AnchorPane.setBottomAnchor(newValue, 0.0d);
AnchorPane.setTopAnchor(newValue, 0.0d);
AnchorPane.setLeftAnchor(newValue, 0.0d);
AnchorPane.setRightAnchor(newValue, 0.0d);
}
}
}
不要忘记将罐子添加到SceneBuilder中。
Image when i try to drag a StackPane into my custom control