【发布时间】:2016-07-03 06:03:42
【问题描述】:
我在ScrollView 中有一个GridPane。我在GridPane 的每个空间中添加图像。首先只有 1 行 3 列。但是当我传递 3 张图像的数量时,我将GridPane 增加一行,并添加表示网格行高度的数字 (130px)。所以这是我的代码。
private void AddItem() {
ImageView image = new ImageView();
image.setImage(new Image("media/logo.jpg"));
image.setFitHeight(50);
image.setFitWidth(100);
if (columns > 2) {//when it reaches the end of the columns
viewGrid.setPrefHeight(viewGrid.getHeight() + 130);//I increase the height of the GridPane
viewGrid.addRow(rows++);//I add a new row
columns=0;//I set the column to 0 again
}
viewGrid.add(image, columns, rows);
columns++;
}
结果
图像开始相互碰撞,而不是保持真实位置:
GridPane 中是否有一些属性可以让我实现所需的行为?
【问题讨论】:
标签: java gridview javafx scrollview