Javafx 2 滚动窗格内的TilePane只占屏幕的一小部分
我有一个由图像组成的TilePane,TilePane中的图像取决于用户选择的文件夹中图像的数量。但是tilepane中没有滚动窗格,所以我决定将tilepane放在滚动窗格中,但我无法控制滚动窗格的高度以占据整个页面Javafx 2 滚动窗格内的TilePane只占屏幕的一小部分,javafx-2,Javafx 2,我有一个由图像组成的TilePane,TilePane中的图像取决于用户选择的文件夹中图像的数量。但是tilepane中没有滚动窗格,所以我决定将tilepane放在滚动窗格中,但我无法控制滚动窗格的高度以占据整个页面 public ScrollPane viewGallery(Stage stage) { ScrollPane root = null; final TilePane tile = new TilePane(); t
public ScrollPane viewGallery(Stage stage)
{
ScrollPane root = null;
final TilePane tile = new TilePane();
try{
root = new ScrollPane();
tile.setPadding(new Insets(5, 5, 5, 5));
tile.setVgap(4);
tile.setHgap(4);
tile.setPrefHeight(stage.getHeight());
tile.setStyle("-fx-background-color: DAE6F3;");
File[] listOfFiles = outputFolder.listFiles();
System.out.println(outputFolder.listFiles().length);
for (File file : listOfFiles) {
System.out.println(file.getPath());
Image image = new Image("file:"+file.getPath());
ImageView iv2 = new ImageView();
iv2.setImage(image);
iv2.setFitWidth(250);
iv2.setPreserveRatio(true);
iv2.setSmooth(true);
iv2.setCache(true);
tile.getChildren().add(iv2);
}
}catch(Exception e)
{
e.printStackTrace();
}
root.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); // Horizontal scroll bar
root.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); // Vertical scroll bar
root.setFitToHeight(true);
root.setFitToWidth(true);
root.setContent(tile);
return root;
}
输出是今生今世的东西。问题不在于滚动窗格或TilePane,我正在将滚动窗格添加到边框窗格,我正在使用:
border.setTop(viewGallery(Stage stage));
将上面的代码更改为下面的代码就解决了我的问题
border.setCenter(viewGallery(Stage stage));
这些文件非常清楚:
顶部和底部子项将调整为其首选高度,并扩展边框窗格的宽度。左侧和右侧子节点的大小将调整为其首选宽度,并在顶部和底部节点之间延伸长度。将调整中心节点的大小,以填充中间的可用空间tile.setMaxHeight(Double.MAX_值);hm.而不是
tile.setPrefHeight(stage.getHeight())代码>,尝试绑定它:tile.prefHeightProperty().bind(stage.heightProperty())代码>。可能是在舞台还没有完全调整好的时候设置了预调高度。您如何将滚动窗格添加到场景中?你在用另一个家长包装它吗?