1

我的应用程序出现奇怪的图形故障。情况是我正在创建一些 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++;
        }
    }
}

我已经尝试简化代码以使其更简洁,但如果需要,我会发布其余部分。

谢谢!

4

1 回答 1

1

我似乎找到了解决方案。从外观上看,这确实是一个错误。我稍后会向 Oracle 报告。似乎问题在于我的 ScrollPane 中有填充。根据我的测试,如果 padding 大于 5,就会出现故障。一种解决方法是将填充分配给父 GridPane 而不是 ScrollPane。

于 2015-08-04T18:40:23.010 回答