gpt4 book ai didi

java - 单击按钮时更改 javafx webview 方向

转载 作者:行者123 更新时间:2023-12-02 02:44:29 26 4
gpt4 key购买 nike

我正在尝试制作一个java程序。用户选择他们的html文件,它将显示在javafx webview(或程序内的另一个Web浏览器)中。我想添加一个按钮来将 webview 方向从水平切换到垂直,反之亦然,用户可以检查他们的 html 文件是否有响应。我不确定是否可以调整当前场景的大小,或者是否可以在两个场景之间setScene或删除和新建场景...

VBox root = new VBox();
VBox root1 = new VBox();

Scene scene = new Scene(root, 900, 500);
Scene scene1 = new Scene(root1, 500, 900);

感谢并抱歉英语语法不好!

最佳答案

以下代码演示了如何动态更改大小:

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class StageTest extends Application{

private static final double WIDTH = 900, HEIGHT = 500;
private Stage stage;
private VBox root;
boolean isVertical = false;

@Override
public void start(Stage stage) throws Exception {

this.stage = stage;
stage.setTitle("Dynamic Stage Resize");

root = new VBox();
root.setAlignment(Pos.CENTER_LEFT);
root.setPrefSize(WIDTH, HEIGHT);

Button addNode = new Button("Change Size");
addNode.setOnAction( e -> changeSize());
root.getChildren().add(addNode);

Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}

void changeSize() {

if(isVertical) {
root.setPrefSize(WIDTH, HEIGHT);
} else {
root.setPrefSize(HEIGHT, WIDTH);
}

isVertical = !isVertical;
stage.sizeToScene();
}

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

关于java - 单击按钮时更改 javafx webview 方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44860416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com