我需要在ScrollPane中相对于鼠标位置放大/缩小。为此,我使用了 answer of this question,到目前为止一切都很好。 我也需要另一件事,当我全屏窗口Vbox填满整个页面时。为此,请更改以下代码:1.将Group的最大大小设置为Double.Max_value:
public panelable(Node target) {
super();
this.target = target;
this.zoomNode = new Group(target);
zoomNode.maxHeight( Double.MAX_VALUE) ;
zoomNode.maxWidth( Double.MAX_VALUE) ;
setContent(outerNode(zoomNode));
setPannable(true);
setFitToHeight(true); //center
setFitToWidth(true); //center
updateScale();
}
2。为VBox声明vgrow:
private Node centeredNode(Node node) {
VBox vBox = new VBox(node);
VBox.setVgrow( node , Priority.ALWAYS);
vBox.setAlignment(Pos.CENTER);
return vBox;
}
但是Group不可调整大小,并且此代码无法正常工作。此外,正如Oracle ScrollPane documentation 所说,我需要将滚动节点包装在Group中。所以,我该怎么办?有解决方案吗?请帮帮我。 这是我的主要课程代码:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
StackPane stackPane = new StackPane() ;
stackPane.setPrefSize( 600, 600);
stackPane.setMaxSize( Double.MAX_VALUE , Double.MAX_VALUE);
stackPane.setStyle( "-fx-background-color: red");
primaryStage.setScene(new Scene( new panelable( stackPane)));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}}