使用FXML创建带有ProgressBar的TableView。我在下面的代码中收到包含ProgressBarTableCell的行的错误如下所示。我提到Link1& Link2但无法弄清楚我在做什么错误。
错误:
'setCellValueFactory(javafx.util.Callback<javafx.scene.control.TableColumn.CellDataFeatures<model.TableDisplayData,java.lang.Double>,javafx.beans.value.ObservableValue<java.lang.Double>>)'
in 'javafx.scene.control.TableColumn' cannot be applied to
'(javafx.util.Callback<javafx.scene.control.TableColumn<model.TableDisplayData,java.lang.Double>,javafx.scene.control.TableCell<model.TableDisplayData,java.lang.Double>>)'
代码:
@FXML
private TableView<TableDisplayData> tvDisplay;
@FXML
private TableColumn<TableDisplayData,String> colCarModel;
@FXML
private TableColumn<TableDisplayData,String> colModelIndicator;
@FXML
private TableColumn<TableDisplayData,Double> colSpeedProgress;
@Override
public void initialize(URL location, ResourceBundle resources) {
colCarModel.setCellValueFactory(new PropertyValueFactory<TableDisplayData, String>("car"));
colModelIndicator.setCellValueFactory(new PropertyValueFactory<TableDisplayData, String>("indicator"));
colSpeedProgress.setCellValueFactory(new PropertyValueFactory<TableDisplayData, Double>("progressBar"));
colSpeedProgress.setCellValueFactory(ProgressBarTableCell.<TableDisplayData> forTableColumn());
}
TableDisplayData的代码:
public class TableDisplayData{
private String car;
private String indicator;
private DoubleProperty progressBar = new SimpleDoubleProperty();
public TableDisplayData(String car, String indicator, double progressBar) {
this.car= car;
this.indicator = indicator;
setProgressBar(progressBar);
}
getters & setters....
答案 0 :(得分:3)
您将cellFactory
与cellValueFactory
混淆。 cellValueFactory
告诉列要显示的数据。 cellFactory
告诉列 如何显示数据。
所以你需要
colSpeedProgress.setCellValueFactory(new PropertyValueFactory<TableDisplayData, Double>("progressBar"));
colSpeedProgress.setCellFactory(ProgressBarTableCell.<TableDisplayData> forTableColumn());
(请注意,第二行更改为setCellFactory
,而不是setCellValueFactory
)。