我想将复选框和文本字段添加到PropertySheet
(ControlsFX
库)的一个属性。有可能吗?所以,我只需要将一些 GUI 元素添加到一个PropertyEditor
中,例如复选框 + 按钮、复选框 + 标签、复选框 + 文本字段等。是否可以覆盖PropertyEditor
来做到这一点?
问问题
153 次
2 回答
0
自己解决了。我试图将复选框 + 组合框添加到 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-13T12:24:26.513 回答