GridView: infinite calls of updateItem method
See original GitHub issueWe’ve been using: FXControls 8.40.14. (JDK 8) Recently we’ve upgraded to: FXControls 11.0.1. (JDK 11)
After upgrade we’ve noticed issues related to GridView. What’s happening is that GridCell#updateItem is called infinitely.
I’ve searched Google group and Github issue tracker but haven’t found anything related…
After investigating it further it turned out that issues appears when animated GIFs are shown inside GridView
.
I’ve prepared SSCCE which can be used to reproduce the issue:
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.controlsfx.control.GridCell;
import org.controlsfx.control.GridView;
import java.util.ArrayList;
import java.util.List;
public class GridViewItemUpdateTest extends Application {
int gridCellUpdateCounter = 0;
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage primaryStage) {
GridView<Image> grid = new GridView<>();
grid.setCellFactory(param -> new GifImageCell());
grid.setItems(FXCollections.observableArrayList(getImagesList()));
grid.setCellHeight(220);
grid.setCellWidth(220);
StackPane stackPane = new StackPane(grid);
stackPane.setPrefSize(260, 440);
Scene scene = new Scene(stackPane);
primaryStage.setScene(scene);
primaryStage.show();
}
private class GifImageCell extends GridCell<Image> {
final StackPane stackPane = new StackPane();
final ImageView imageView = new ImageView();
public GifImageCell() {
imageView.setFitHeight(200);
imageView.setFitWidth(200);
stackPane.setMinWidth(220);
stackPane.setMinHeight(220);
stackPane.getChildren().add(imageView);
stackPane.setPadding(new Insets(10));
}
@Override
protected void updateItem(Image image, boolean empty) {
super.updateItem(image, empty);
System.out.println(++gridCellUpdateCounter);
setText(null);
if (empty || image == null) {
setGraphic(null);
} else {
imageView.setImage(image);
setGraphic(stackPane);
}
}
}
private List<Image> getImagesList() {
final List<Image> images = new ArrayList<>();
final Image gifImage = new Image("https://thumbs.gfycat.com/TepidVariableBluetickcoonhound-small.gif", 200, 200, true, false);
for (int i = 0; i < 10; i++) {
images.add(gifImage);
}
return images;
}
}
When running this example with:
- FXControls 8.40.14. (JDK 8), the updateItem will be called 19 times initially
- FXControls 11.0.1. (JDK 11), the updateItem will be called infinitely
After further investigation I was able to found out that this issue is most probably related to this change (see GridRow.java:106
):
https://github.com/controlsfx/controlsfx/commit/8f06811e9487fd171eed835c7585c9ef2cf1be76#diff-056220662a7039e7b16736b23e4a7de2R106
Skipping line at GridRow.java:106
when debugging seems to fix the issue with infinite GridCell#updateItem(...)
calls.
Unfortunately this issue makes GridView
unusable for us.
Are there any workarounds we could apply to overcome this?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Same issue with custom GridCell with images. Very weird. I had some nothing code in the updateItem method, simply setting the text of a label. Removing it stopped the infinite spin but it still calls updateItem a lot.
Hello,
I’ve been examining a similar issue that I have encountered. I believe a
GridCell
responds to an update in index by updating itself in this code, and I’m seeing myGridCell
infinitely call update due to index changes that occur here. Is there any need to callupdateIndex(-1)
here before callingupdateIndex
for the correct cell index? Thank you for all the wonderful work on this project!