javafx 创建图像分页

示例

ArrayList<String> images = new ArrayList<>();
images.add("some\\cool\\image");
images.add("some\\other\\cool\\image");
images.add("some\\cooler\\image");

Pagination p = new Pagination(3);
p.setPageFactory(n -> new ImageView(images.get(n)));

请注意,路径必须是url,而不是文件系统路径。

这个怎么运作

p.setPageFactory(n -> new ImageView(images.get(n)));

其他一切都只是绒毛,这才是真正的工作正在进行的地方。setPageFactory接受带int的回调,并返回该索引处所需的节点。第一页映射到列表中的第一项,第二页映射到列表中的第二项,依此类推。