Question
Ma question est relativement simple, j'ai créé un custom control et je voudrais drag and drop une "Node" depuis "Scenebuilder" à l'intérieur. (Voir l'image en dessous)
Par exemple
public class CustomControl extends Control {}
Je crée une "StackPane", Ensuite j'ajoute mon composant à l'intérieur, ensuite j'aimerais ajouter une autre "StackPane" dans mon composant.
Cette dernière partie me pose problème
Exemple dans JavaFx
Vous pouvez regarder ces Class pour vous donner une idée de ce que j'essaye de faire.
public class SplitPane extends Control {}
SplitPane JavaDoc
Ou alors :
public class TitledPane extends Labeled {}
TitledPane JavaDoc
Environnement
Mon Scene builder version : 8.5.0 [Gluon]
Ma version de Java : 1.8.0_191 [Oracle]
Exemple de custom Control
Ceci est un exemple simple
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
@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);
}
} |
Le skin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
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);
}
}
} |
Ne pas oublier d'importer votre jar dans "SceneBuilder".
Dans SceneBuilder
Image quand j'essaye de drag and drop une "StackPane" dans mon composant à l'intérieur de "SceneBuilder".
Merci d'avance pour votre aide.
Partager