Zooming in JavaFx: ScrollEvent is consumed when content size exceeds ScrollPane viewport

前端 未结 3 2157
抹茶落季
抹茶落季 2020-12-31 14:18

I have an application that requires zoom inside a ScrollPane, but with my current approach I\'m still facing 2 challenges. In order to replicate the problem, I have written

3条回答
  •  悲哀的现实
    2020-12-31 14:45

    The following workaround seems to be giving better results:

    1. Set onscroll event on the outer group to steal the event from the scroll pane.
    2. Add a opaque rectangle which covers the whole screen, so that you don't miss the scroll event. Apparently you can miss scroll event if you don't hit a shape.

      Rectangle opaque = new Rectangle(0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
      opaque.setOpacity( 0 );
      outerGroup.getChildren().add( opaque );
      outerGroup.setOnScroll(new ZoomHandler(innerGroup));
      

提交回复
热议问题