我在scenebuilder中构建了一个gridpane。我在每个单元格中都有一个图像视图。我想构建一个动态图库图片。我想删除每一行中的最后一个图像并将其添加到下一行的第一列?我可以这样做吗?我是javafx的生儿,请帮助我:( 谢谢
答案 0 :(得分:0)
未经测试,但这应该有效:
// if you know how many columns you have (and their indexes) this step is unnecessary:
int minColIndex = Integer.MAX_VALUE ;
int maxColIndex = Integer.MIN_VALUE ;
for (Node node : gridPane.getChildren()) {
int colIndex = GridPane.getColumnIndex(node);
if (colIndex < minColIndex) minColIndex = colIndex ;
if (colIndex > maxColIndex) maxColIndex = colIndex ;
}
// Update row and column indexes:
for (Node node : gridPane.getChildren()) {
int colIndex = GridPane.getColumnIndex(node);
if (colIndex == maxColIndex) {
int rowIndex = GridPane.getRowIndex(node);
GridPane.setRowIndex(node, rowIndex+1);
GridPane.setColIndex(node, minColIndex);
} else {
GridPane.setColIndex(node, colIndex + 1) ;
}
}
你确定TilePane不能更好地满足你的需求吗?