Search code examples
javajavafxscrollpanevisual-glitchgridpane

JavaFX Graphical Glitch


I'm experiencing a weird graphical glitch on my application. The situation is that I am creating some GridPanes and adding them to a parent GridPane which is inside a ScrollPane. However, upon scrolling, some weird glitches begin occurring. Here is a picture: (Sorry for having to use links, I don't have enough reputation to post images).

http://s11.postimg.org/x9eg8bz4z/Glitch.png

Here is a picture of what it should look like:

http://s11.postimg.org/cqjk39l7n/Normal.png

Here is my code:

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

I have tried simplifying the code to make it cleaner, but I will post the rest if needed.

Thank you!


Solution

  • I seem to have found the solution. By the looks of it, this really is a bug. I will report it to Oracle later. It seems the problem was that I had padding in my ScrollPane. By my testing, if padding was greater than 5, the glitches would occur. A workaround is to assign the padding to the parent GridPane rather than the ScrollPane.