如何使用javafx查看水平换行和垂直滚动的单元格

How to use javafx to view cells that wraps horizontally and scrolls vertically

我正在尝试确定如何使用 javafx 来显示类似于 Windows Explorer 的单元格(图像缩略图或图像),其中图像显示在水平边界处换行但垂直滚动的行中方向。

表视图是一种使用方法,然后在调整视图大小时更新列号吗?一点帮助将不胜感激。更好的是一个简单的示例代码。

我是这个论坛的新手,我搜索过但无法真正开始。

谢谢

包装 FlowPane inside a ScrollPane 将是解决问题的更简单方法。

示例:

这使用了一些带有数字而不是图像的矩形,但我认为这足以了解如何使用 Layouts:

FlowPane contentContainer = new FlowPane();
contentContainer.setVgap(10);
contentContainer.setHgap(10);

ScrollPane scroll = new ScrollPane(contentContainer);
scroll.setFitToWidth(true);

// fill FlowPane with some content
ArrayList<Node> content = new ArrayList<>();

for (int i = 0; i < 15; i++) {
    Text text = new Text(Integer.toString(i));
    text.setFill(Color.YELLOW);
    StackPane pane = new StackPane(text);
    pane.setStyle("-fx-background-color: blue;");
    pane.setPrefSize(50, 50);
    content.add(pane);
}

contentContainer.getChildren().setAll(content);