4

I have noticed that ListView does not behave the same as ScrollPane in terms of scrolling on Embedded Devices with touch. I cannot find a way to make ListView pannable, so as to make it scroll when dragging, and bounce back when off bounds (see example).

enter image description here

You can simulate touching by setting the JVM arguments below.

-Dcom.sun.javafx.isEmbedded=true
-Dcom.sun.javafx.touch=true
public class ScrollTouch extends Application  {

  @Override
  public void start(Stage primaryStage) throws Exception { 
    primaryStage.setTitle("ScrollBar VS ListView");

    // ScrollPane
    ScrollPane scrollPane = new ScrollPane();
    VBox spContent = new VBox();
    for(int i=0; i<20; i++)
     spContent.getChildren().add(getLabel("Label No." + i));
    
    scrollPane.setPrefWidth(150);
    scrollPane.setContent(spContent);
    scrollPane.setPannable(true);

    // ListView
    ListView<Label> listView = new ListView<Label>();
    for(int i=0; i<20; i++)
     listView.getItems().add(getLabel("Label No." + i));
    
    listView.setFocusTraversable(false);
    
    HBox rootPane = new HBox();
    rootPane.getChildren().addAll(scrollPane,listView);

    Scene scene = new Scene(rootPane, 400, 300);
    primaryStage.setScene(scene);
    primaryStage.show();
  }
  
  private Label getLabel(String text) {
      Label label = new Label(text);
      label.setPrefHeight(20);
      return label;
  }

  public static void main(String[] args) {
    Application.launch(args);
  }
}
Clifford
  • 88,407
  • 13
  • 85
  • 165
javasuns
  • 1,061
  • 2
  • 11
  • 22
  • hmm .. that's a bit weird: virtualFlow (the collaborator responsible for scrolling, no ScrollPane involved) does support pannable which the ListViewSkin sets to true only if _-Djavafx.scene.control.skin.ListViewSkin.pannable=true_ ... sounds like a bug to me – kleopatra Jan 17 '21 at 11:55
  • an aside: don't use nodes as data in a listView that's destroying the whole purpose of a virtualized control :) – kleopatra Jan 17 '21 at 11:58
  • @kleopatra well, I know what you mean, but that's irrelevant with the issue. I just wanted a small piece of code to demonstrate the problem. – javasuns Jan 17 '21 at 16:31
  • using a simple string would have been cleaner and just as small ;) – kleopatra Jan 17 '21 at 17:00
  • Any progress on this? I have the same issue with TableView. I see it was working in previous versions but been removed ? https://bugs.openjdk.java.net/browse/JDK-8112717 – tec Jul 28 '21 at 10:06

0 Answers0