0

下图解释了我如何填充我的表格: 在此处输入图像描述

如您所见,Installments一旦相关行的列复选框未选中,我需要禁用列按钮Collected,反之亦然。

到目前为止,这是我的方法:

colected_column.setCellValueFactory((TableColumn.CellDataFeatures<Member, CheckBox> param) -> {
        Member mRow = param.getValue(); // type objects contained within the TableView
        CheckBox checkBox = new CheckBox();
        checkBox.selectedProperty().addListener((ov, old_val, new_val) -> {

            // javafx.scene.control.Button typed ObservableValue returns as cell value
            Button button = installments_column.getCellData(mRow);
            button.setDisable(!new_val);
        });

      ...
      return new SimpleObjectProperty<>(checkBox);
}

但是这种方法不符合要求,按钮一直处于启用状态。任何帮助都是不言而喻的。谢谢你。

在此处输入图像描述

4

1 回答 1

2

不要将节点放在您的项目类中。这样一来,您就破坏了以下主要好处TableView:将节点的数量限制为显示内容所需的数量。

您最好BooleanPropertyMember对象中使用 a ,CheckBoxTableCell用于显示CheckBoxes 并为分期付款列使用自定义单元格:

TableColumn<Member, Boolean> colected_column = ...;

colected_column.setCellValueFactory((TableColumn.CellDataFeatures<Member, Boolean> param) -> {
    Member mRow = param.getValue(); // type objects contained within the TableView
    return nRow.collectedProperty();
});
colected_column.setCellFactory(CheckBoxTableCell.forTableColumn(colected_column));
TableColumn<Member, Boolean> installmentsColumn = ...;
installmentsColumn.setCellValueFactory(cd -> cd.getValue().collectedProperty());
installmentsColumn.setCellFactory(column -> new TableCell<Member, Boolean>() {

    private final Button button = new Button("View Info");

    {
        button.setOnAction(evt -> {
            Member member = (Member) getTableRow().getItem();

            // TODO: handle button click
        });
    }

    @Override
    protected void updateItem(Boolean item, boolean empty) {
        super.updateItem(item, empty);

        if (empty || item == null) {
            setGraphic(null);
        } else {
            setGraphic(button);
            button.setDisable(!item);
        }
    }
});
public class Member {
    private final BooleanProperty collected = new SimpleBooleanProperty(true);

    public void setCollected(boolean value) {
        collected.set(value);
    }

    public boolean isCollected() {
        return collected.get();
    }

    public BooleanProperty collectedProperty() {
        return collected;
    }

    ...
}
于 2018-04-30T11:11:03.013 回答