简体   繁体   中英

Smooth Panning in ScrollPane Javafx

I have a scrollPane with pannable enabled. When panning with a large image the transformation "lags" behind the mouse making for a "blocky" transformation. Is there a way to fix this? There is not much code that is really relevant here to post if you need more specifics just ask.

I realize this is an old post, but others might need help in this area. What I did to solve this problem is to create a Transition object, and under the interpolate function, set the ScrollPane vValue or hValue equal to itself plus 0.001 depending on how fast you want to pan. vValue and hValue are the viewing locations on the ScrollPane, so basically you're just slowly incrementing what your viewing, so it looks like panning but its not. Here's an example from a project I'm working on where you can "pan" down or up with KeyEvents.

@FXML
ScrollPane scroll;

private Transition down;
private Transition up;

public void initialize(){

    this.down = new Transition() {
        {
            setCycleDuration(Duration.INDEFINITE);
        }
        @Override
        protected void interpolate(double v) {
            scroll.setVvalue(scroll.getVvalue()+0.001);
        }
    };

    this.up = new Transition() {
        {
            setCycleDuration(Duration.INDEFINITE);
        }
        @Override
        protected void interpolate(double v) {
            scroll.setVvalue(scroll.getVvalue()-0.001);
        }
    };
}


@FXML
private void handleKeyPress(KeyEvent event){
    if(event.getCode() == KeyCode.S){
        down.play();
    }
    if(event.getCode() == KeyCode.W){
        up.play();
    }
}

@FXML
private void handleKeyRelease(){
    this.down.stop();
    this.up.stop();
}

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