我的应用程序出现奇怪的图形故障。情况是我正在创建一些 GridPane 并将它们添加到 ScrollPane 内的父 GridPane。然而,在滚动时,开始出现一些奇怪的故障。这是一张图片:(抱歉不得不使用链接,我没有足够的声誉来发布图片)。
http://s11.postimg.org/x9eg8bz4z/Glitch.png
这是它应该是什么样子的图片:
http://s11.postimg.org/cqjk39l7n/Normal.png
这是我的代码:
private static class Controller implements Initializable {
@FXML private GridPane projectsPane;
@Override
public void initialize(URL location, ResourceBundle resources) {
//I first create some objects to be used when
//creating the GridPanes in the following loop,
//but I have removed the code for simplicity
for(AvailableProject availableProject : availableProjects) {
GridPane projectPane = new GridPane();
projectPane.setBackground(new Background(new BackgroundFill(Color.DARKGREY, CornerRadii.EMPTY, Insets.EMPTY)));
ColumnConstraints column1 = new ColumnConstraints();
column1.setPercentWidth(50);
ColumnConstraints column2 = new ColumnConstraints();
column2.setPercentWidth(50);
projectPane.getColumnConstraints().addAll(column1, column2);
projectPane.setPadding(new Insets(5));
Label projectName = new Label(availableProject.projectName);
GridPane.setValignment(projectName, VPos.CENTER);
projectPane.add(projectName, 0, 0);
TextFlow description = new TextFlow(new Text(availableProject.description));
description.setMaxSize(200, 100);
GridPane.setValignment(description, VPos.CENTER);
projectPane.add(description, 0, 1);
Label category = new Label(availableProject.category);
GridPane.setValignment(category, VPos.CENTER);
GridPane.setHalignment(category, HPos.RIGHT);
projectPane.add(category, 1, 0, 1, 2);
projectsPane.add(projectPane, 0, yRow);
yRow++;
Pane pane = new Pane();
pane.setMinHeight(15);
projectsPane.addRow(yRow, pane);
yRow++;
}
}
}
我已经尝试简化代码以使其更简洁,但如果需要,我会发布其余部分。
谢谢!