0
我期待在JavaFX 8中實現基本的可擴展自定義控件,其中包含添加了其他控件的窗格。如何實現基於窗格的自定義JavaFX控件
因此,例如,它可以包含GridPane
,其持有TextField
,Button
和CheckBox
。
我不想子類Pane
或GridPane
,因爲我不想將這些API公開給用戶。所以,「一個由網格窗格組成的節點」與「一個擴展網格窗格的節點」相對。
我看到延伸Region
或Control
是可能的,這是推薦?將窗體大小和佈局委派給窗格需要什麼?
public class BasePaneControl extends Control {
private final Pane pane;
public BasePaneControl(Pane pane) {
this.pane = pane;
getChildren().add(pane);
}
// What do I need to delegate here to the pane to get sizing
// to affect and be calculated by the pane?
}
public class MyControl extends BasePaneControl {
private final GridPane gp = new GridPane();
public MyControl() {
super(gp);
gp.add(new TextField(), 0, 0);
gp.add(new CheckBox(), 0, 1);
gp.add(new Button("Whatever"), 0, 2);
}
// some methods to manage how the control works.
}
我需要幫忙實施BasePaneControl
以上請。