JavaFX图形故障

时间:2015-08-03 21:42:30

标签: java javafx scrollpane visual-glitch gridpane

我在应用程序上遇到了奇怪的图形故障。情况是我正在创建一些GridPanes并将它们添加到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++;
        }
    }
}

我尝试过简化代码以使其更清晰,但如果需要,我会发布其余代码。

谢谢!

1 个答案:

答案 0 :(得分:1)

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