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

[ListView] Scrollbar thumb has wrong size when list has only one cell


    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u5
    • Fix Version/s: tbd
    • Component/s: javafx


      I have following problem, in my ListView the scrollbar fills 100% of its container so that it is impossible to use. This happens when the ListView has only one cell which is also bigger than its viewport. I wrote a small example to show it:

      public class ExtendedScrollbarWrongHeight2 extends Application {
          private BorderPane borderPane;

          public static void main(String[] args) {

          public void start(Stage primaryStage) throws Exception {
              final Parent parent = createParent();
              final Scene scene = new Scene(parent, 640, 480);


          protected Parent createParent() {
              final ObservableList<String> items = FXCollections.observableArrayList();
              items.add("Scroll Down 1");
      // items.add("Scroll Down 2"); // uncomment and bug is fixed

              final ListView<String> listView = new ListView<>();
              listView.setCellFactory(param -> {
                  return new CellCenter();

              return listView;

          private static class CellCenter extends ListCell<String> {
              private final Label label = new Label();

              protected void updateItem(String item, boolean empty) {
                  if (item == null || empty) {
                  } else {
                      label.setStyle("-fx-background-color: indianred; -fx-border-color: darkred;-fx-border-width: 1px;-fx-font-size: 40px;");


      When I add a second item to the ListView the scrollbar thumb has the correct size, but I also need it for single cells. I used the debugger and found a method updateScrollBarsAndCells() in VirtualFlow which is responsible for the calculation. It seems that the bug is known, see the comments in the last if case, but I found only one similar issue here (RT-29624) and I was not sure if it is the same problem.

      if (recreate && (lengthBar.isVisible() || BehaviorSkinBase.IS_TOUCH_SUPPORTED)) {
                  int numCellsVisibleOnScreen = 0;
                  for (int i = 0, max = cells.size(); i < max; i++) {
                      T cell = cells.get(i);
                      if (cell != null && !cell.isEmpty()) {
                          sumCellLength += (isVertical ? cell.getHeight() : cell.getWidth());
                          if (sumCellLength > flowLength) {


                  if (numCellsVisibleOnScreen == 0 && cellCount == 1) {
                          // special case to help resolve RT-17701 and the case where we have
                      // only a single row and it is bigger than the viewport
                      lengthBar.setVisibleAmount(flowLength / sumCellLength);
                  } else {
                      lengthBar.setVisibleAmount(numCellsVisibleOnScreen / (float) cellCount);

      Could you give me an alternative way how I can recalculate the scrollbar thumb size. I tried it by accessing the scrollbars via the ListView and it works only for selection. When I have two selected items and deselect one of it, it doesn't work. My helper method gets called before updateScrollBarsAndCells() and so the size will be overwritten.




            • Assignee:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: