Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8097108

[VirtualFlow] Cells with a height depending on their width are not correctly resized and positioned



    • Bug
    • Resolution: Fixed
    • P3
    • 8u40
    • 8u20, 8u40
    • javafx
    • Windows 7 SP 1 64bit
      Java 8u20 (32bit) released version
      Java 8u40 b15 (32bit)


      When using a FlowPane inside the cells of a ListView, the cells are not always of the correct size (e.g. not high enough for a vertical ListView) and at the correct position (e.g. cells overlap vertically for a vertical ListView). This seems to be only an issue when a scrollbar is displayed.

      Below is a piece of code which should exemplify the described behavior.

      Explanation for the example:
      When executed, the application should show a ListView whose cells overlap and whose height is too low (-> only the upper half of the last line of each cell is shown and the bottom red border is not displayed at all). As soon as the window is resized to be wider, the layout is corrected. However, when the width of the window is adjusted again such that a further line is necessary for the text (but would be not if the width was 1 or 2 pixels more), the wrong layout should show up again.

      Possible source of error:
      The method fitCells() of the class VirtualFlow adjusts the size of the cells when scrollbars are displayed. However, it adjusts only one of the dimensions without recalculating the other one. Shouldn't the method fitCells() recalculate the other dimension like the method resizeCellSize() does?
      Additionally, the size of the cells is adjusted after their position was determined. Shouldn't the method fitCells() be called before the positioning happens in the method updateScrollBarsAndCells()?

      It would be good to know whether these assumptions are correct and whether a workaround exists.

      import java.util.LinkedList;
      import java.util.List;

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.ListCell;
      import javafx.scene.control.ListView;
      import javafx.scene.layout.FlowPane;
      import javafx.stage.Stage;

      public class ListViewWithFlowPaneTester extends Application {

          public static void main(String[] args) {

          public void start(Stage primaryStage) {
              ListView<Integer> listView = new ListView<>();

              ObservableList<Integer> observableList = FXCollections.observableArrayList();
              listView.setCellFactory(param -> new MyCell());

              for (int i = 0; i < 10; i++) {

              Scene scene = new Scene(listView, 300, 200);


          private static class MyCell extends ListCell<Integer> {

              private FlowPane flowPane;

              private MyCell() {
                  flowPane = new FlowPane();
                  flowPane.setStyle("-fx-border-width: 1; -fx-border-color: red");

              protected void updateItem(Integer item, boolean empty) {
                  super.updateItem(item, empty);
                  if (empty || item == null) {

                  List<Label> labels = new LinkedList<>();
                  for (int i = 0; i < item; i++) {
                      labels.add(new Label("Hallo"));




            jgiles Jonathan Giles
            duke J. Duke
            1 Vote for this issue
            2 Start watching this issue