简体   繁体   English

JavaFX-滚动上的ScrollPane内容失真问题

[英]JavaFX - ScrollPane content distorting issue on scroll

I encountered a problem with the rendering of a JavaFX scrollpane. 我在渲染JavaFX滚动窗格时遇到问题。 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 . 当将填充应用于ScrollPane时, Spinner渲染会以某种方式失真。 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: 解决方法是将填充添加到另一个外部布局而不是ScrollPane:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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