简体   繁体   中英

JavaFX - ScrollPane content distorting issue on scroll

I encountered a problem with the rendering of a JavaFX scrollpane. Sometimes when I scroll the pane, the contained view looks "teared" or simply missing certain details. The tearing can be fixed if the user changes the current focus in the application (ie by clicking a new element). Please see the image bellow.

滚动视图,带有撕裂

I made an example program that can replicate the issue:

public class ScrollingView extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Scrollview!");        
        ScrollPane root = new ScrollPane();
        root.paddingProperty().setValue( new Insets(10, 10, 10, 10));
        GridPane grid = new GridPane();     

        for(int i = 0; i < 20; i++)
            grid.addRow( i, createSpinner() );

        root.setContent(grid);
        root.vvalueProperty().addListener( (ov, oldV, newV) -> root. );

        primaryStage.setScene(new Scene(root, 300, 150));
        primaryStage.show();
    }

    private Node[] createSpinner(){
        Node[] nodes = new Node[2];

        nodes[0] = new Label("Spinner");

        Spinner<Integer> spinner = new Spinner<>();
        spinner.setEditable(false);
        IntegerSpinnerValueFactory spinnerFactory = new IntegerSpinnerValueFactory(1, 10, 5, 1);
        spinner.setValueFactory(spinnerFactory);    
        nodes[1] = spinner;

        return nodes;
    }
}

I googled the issue but couldn't come up with a solution. Does anyone know what causes the issue, and is there a way to fix it?

Thanks // Simon

Somehow the Spinner rendering distorts when the padding is applied to ScrollPane . Commenting out the

root.paddingProperty().setValue( new Insets(10, 10, 10, 10));

resolves the issue. It may be a bug, and you would prefer to file it. Adding padding to another outer layout instead of ScrollPane ca be an option as workaround:

VBox vbox =new VBox(root);
vbox.setPadding( new Insets(10, 10, 10, 10));
primaryStage.setScene(new Scene(vbox, 300, 150));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM