gpt4 book ai didi

JavaFx WebView 自动刷新?

转载 作者:行者123 更新时间:2023-11-30 07:41:00 24 4
gpt4 key购买 nike

我想自动刷新 JavaFX WebView。你能帮我吗?估计需要每10秒刷新一次

package ui;

import java.io.IOException;

import host.*;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class MainUİ extends Application {

@Override
public void start(Stage primaryStage) throws IOException {
StackPane root = new StackPane();
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
//get read .txt file and connect hostinfo
GetHost host = new GetHost();
String hostinfo = host.getHost();
webEngine.load(hostinfo);
root.getChildren().add(webView);
Scene scene = new Scene(root);
primaryStage.setTitle("Evren-Software");
primaryStage.setScene(scene);
primaryStage.show();
}

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

}

我要在大屏幕上做一个镜像,所以我需要刷新。我将它与 .reload 一起使用,但没有用。每 10 秒

最佳答案

您可以使用时间轴每 10 秒重新加载一次页面:

WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();

KeyFrame keyFrame = new KeyFrame(Duration.seconds(10), event -> {
webEngine.reload();
event.consume();
});
Timeline timeline = new Timeline(keyFrame);
timeline.setCycleCount(Animation.INDEFINITE);

GetHost host = new GetHost();
String hostinfo = host.getHost();
webEngine.load(hostinfo);
timeline.play();

关于JavaFx WebView 自动刷新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56688910/

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