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

ScrollEvent not fired in ListView, TableView, ScrollPane etc.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • 8u40
    • 8u25
    • javafx
    • Windows 7 Enterprise 64-bit, JDK1.8-25

      When I register a handler for a ListView by calling listView.setOnScroll(...), my handler would never be called with the exception of scrolling by mouse wheel beyond the scroll limits.

      My thought of setOnScroll is, that the handler get called when the user scrolls the content by ScrollBar, mouse wheel (or gesture) and also by keyboard. Please correct me if I misunderstood the method signature.

      Here is a code snippet to test the (in my opinion) wrong behavior. I think the "mistake" happens in VirtualFlow by consuming ScrollEvent.

      {code:title=SimpleScrollApp.java|borderStyle=solid}
      package simplescrolltest;

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.input.ScrollEvent;
      import javafx.scene.layout.AnchorPane;
      import javafx.stage.Stage;

      public class SimpleScrollApp extends Application {
          private final ObservableList<String> data = FXCollections.observableArrayList();
          
          @Override
          public void start(Stage primaryStage) {
              
              for (int i = 0; i < 100; i++) {
                  data.add(String.format("ScrollMe " + i));
              }

              ListView listView = new ListView();
              listView.setItems(data);
              
              listView.setOnScroll((ScrollEvent event) -> {
                  // This event handler is called only if we scroll by mouse wheel beyond the limits.
                  // No scrolling from ScrollBar nor KeyBoard (PageUp/Down) is handled.
                  System.out.println("ListView.onScroll handler called: " + event);
              });
              
              AnchorPane root = new AnchorPane();
              root.getChildren().add(listView);
              AnchorPane.setTopAnchor(listView, 0.0);
              AnchorPane.setBottomAnchor(listView, 0.0);
              AnchorPane.setLeftAnchor(listView, 0.0);
              AnchorPane.setRightAnchor(listView, 0.0);
              
              Scene scene = new Scene(root, 300, 250);
              
              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }
      {code}

            jgiles Jonathan Giles
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: