1

Am creating a TableView with ProgressBar using FXML. I am getting a error as below for the line which contains ProgressBarTableCell in the code below. I referred to Link1 & Link2 but unable to figure out what mistake I am doing.

Error:

'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>>)'

Code:

@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());
}

Code for 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....
Community
  • 1
  • 1
iCoder
  • 1,406
  • 6
  • 16
  • 35

1 Answers1

3

You are confusing the cellFactory with the cellValueFactory. The cellValueFactory tells the column what data to display. The cellFactory tells the column how to display the data.

So you need

colSpeedProgress.setCellValueFactory(new PropertyValueFactory<TableDisplayData, Double>("progressBar"));
colSpeedProgress.setCellFactory(ProgressBarTableCell.<TableDisplayData> forTableColumn());

(note the second line is changed to setCellFactory, not setCellValueFactory).

James_D
  • 201,275
  • 16
  • 291
  • 322