0

我想将复选框和文本字段添加到PropertySheetControlsFX库)的一个属性。有可能吗?所以,我只需要将一些 GUI 元素添加到一个PropertyEditor中,例如复选框 + 按钮、复选框 + 标签、复选框 + 文本字段等。是否可以覆盖PropertyEditor来做到这一点?

在此处输入图像描述 在此处输入图像描述

4

2 回答 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 回答
0

您还可以将多个节点包装在单个父级中。[参见此处][1]

于 2016-05-13T11:50:45.427 回答