我想在JavaFX 8中创建一个自定义控件。它看起来像一个DatePicker或ColorPicker控件,但是在ColorPicker的情况下,不是在DatePicker和Color调色板的情况下显示弹出列表,我想改变弹出窗口内容展示了一个有趣的舞台。 DatePicker和ColorPicker子类ComboBoxBase和ComboBoxPopupControl for Skining.Well我不知道这是否是正确的方法。那么,我怎样才能创建这种控件。
这是一个起点:
public class StagePopupControl extends ComboBoxBase<String> {
public StagePopupControl() {
}
@Override
protected Skin<?> createDefaultSkin() {
return new StagePopupControlSkin(this); // unfortunately the compiler shows an error "Make 'createDefaultSkin' return 'StagePopupControlSkin'"
}
}
public class StagePopupControlSkin extends ComboBoxPopupControl<String> {
AnchorPane root = new AnchorPane();
public StagePopupControlSkin(ComboBoxBase comboBox, ComboBoxBaseBehavior behavior) {
super(comboBox, behavior);
root.getChildren().addAll(new DatePicker(), new TextArea());
}
@Override
protected Node getPopupContent() {
return root;
}
@Override
public Node getDisplayNode() {
return root;
}
}