JavaFX 图形故障

JavaFX Graphical Glitch

我的应用程序出现奇怪的图形故障。情况是我正在创建一些 GridPanes 并将它们添加到 ScrollPane 内的父 GridPane。然而,在滚动时,一些奇怪的故障开始发生。这是一张照片: (很抱歉不得不使用链接,我没有足够的声誉来 post 图片)。

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++;
        }
    }
}

我已尝试简化代码以使其更清晰,但如果需要,我会 post 其余部分。

谢谢!

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