我想将复选框和textfield添加到PropertySheet (ControlsFX库)的一个属性中。有可能吗?因此,我只需要将一些GUI元素一起添加到一个PropertyEditor中,例如复选框+按钮、复选框+标签、复选框+ textfield等等。是否可以重写PropertyEditor来完成这些操作?


发布于 2016-05-13 12:24:26
我自己解决的。我尝试将复选框+组合框添加到HBox中。下面的代码,它能工作。
public static final <T> PropertyEditor<?> createCheckBoxLinkEditor(PropertySheet.Item property,
final Collection<T> choices) {
ComboBox<T> comboBox = new ComboBox<T>();
comboBox.setCellFactory((ListView<T> p) -> new ListCell<T>() {
@Override
protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
} else if (item instanceof Class) {
setText(((Class) item).getSimpleName());
} else {
setText(item.toString());
}
}
});
HBox hbox = new HBox(5);
CheckBox checkBox = new CheckBox();
hbox.getChildren().add(checkBox);
hbox.getChildren().add(comboBox);
//hbox.getA
//comboBox.setConverter(value);
return new AbstractPropertyEditor<T, HBox>(property, hbox) {
{
comboBox.setItems(FXCollections.observableArrayList(choices));
//new AutoCompleteComboBoxListener(comboBox);
new SelectKeyComboBoxListener(comboBox);
}
@Override
protected ObservableValue<T> getObservableValue() {
return comboBox.getSelectionModel().selectedItemProperty();
}
@Override
public void setValue(T value) {
comboBox.getSelectionModel().select(value);
}
};
}发布于 2016-05-13 11:50:45
您还可以将多个节点封装在一个单亲中。

https://stackoverflow.com/questions/37209161
复制相似问题