只有當TableColumn<CustomObject, Boolean> tableColumnTwo
複選框被選中時,我纔會根據CustomObject
中的字段值禁用TableColumn<CustomObject, String> tableColumn
。我可以禁用內部但不知道如何檢查裏面updateItem
複選框的狀態的文本框下面是相關的代碼片段,會非常感激,如果任何人都可以在這個JavaFX根據複選框狀態禁用TableColumn
@FXML
private TableColumn<CustomObject, Boolean> tableColumnTwo;
@FXML
private TableColumn<CustomObject, String> tableColumn;
tableColumn.setCellFactory(
new Callback<TableColumn<CustomObject, String>, TableCell<CustomObject, String>>() {
@Override
public TableCell<CustomObject, String> call(TableColumn<CustomObject, String> paramTableColumn) {
return new TextFieldTableCell<CustomObject, String>(new DefaultStringConverter()) {
@Override
public void updateItem(String s, boolean empty) {
super.updateItem(s, empty);
TableRow<CustomObject> currentRow = getTableRow();
if(currentRow.getItem() != null && !empty) {
if (currentRow.getItem().getPetrified() == false) { // Need to check if checkbox is checked or not
setDisable(true);
setEditable(false);
this.setStyle("-fx-background-color: red");
} else {
setDisable(false);
setEditable(true);
setStyle("");
}
}
}
};
}
});
https://stackoverflow.com/help/how-to-ask或者換句話說:請提供一個可運行的示例,說明你在做什麼以及如何達不到目標:) – kleopatra