I've been working with Table View in Javafx, and I want to dynamically control the cell on a button click which itself is too part of Table View. I tried it to do it myself, but its not working as it should be. So help is needed as em not able to do it.
Button TableCell code:
dlColumn.setCellValueFactory(new PropertyValueFactory<>(""));
dlColumn.setCellFactory(new Callback<TableColumn<SharedFileInfo, String>, TableCell<SharedFileInfo, String>>() {
@Override
public TableCell<SharedFileInfo, String> call(TableColumn<SharedFileInfo, String> param) {
final TableCell<SharedFileInfo, String> cell;
cell = new TableCell<SharedFileInfo, String>() {
final Button downloadButton = new Button();
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
setText(null);
} else {
downloadButton.setOnAction((ActionEvent ae) -> {
progressColumn.setCellValueFactory(new PropertyValueFactory<>("progress"));
progressColumn.setCellFactory(new Callback<TableColumn<SharedFileInfo, Double>, TableCell<SharedFileInfo, Double>>() {
@Override
public TableCell<SharedFileInfo, Double> call(TableColumn<SharedFileInfo, Double> param) {
final ProgressBar progressBar = new ProgressBar();
final TableCell<SharedFileInfo, Double> cell;
cell = new TableCell<SharedFileInfo, Double>() {
@Override
protected void updateItem(Double item, boolean empty) {
super.updateItem(item, true);
if (empty) {
setGraphic(null);
setText(null);
} else {
SharedFileInfo sharedinfo = getTableView().getItems().get(this.getIndex());
progressBar.progressProperty().bind(sharedinfo.getProgress());
setGraphic(progressBar);
progressBar.prefWidthProperty().bind(this.widthProperty());
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
}
}
};
return cell;
}
});
});
setGraphic(downloadButton);
setText(null);
}
}
};
return cell;
}
});
Before clicking button, all seems to work as expected, but when I click the button, the whole progress
column get filled with empty Progress Bars
which is what I don't want to. I want, whenever a user clicks button, only that row shows the Progress Bar
and all rest sets to setGraphic(null);
. Please help me with this.!>