JavaFx之WebView(二十五)
jfx的web引擎已经几百年没更新,早就放弃了,写写demo还是不错。jdk8u202还能跑vue 3.0项目
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class Test03 extends Application {
@Override
public void start(Stage stage) throws Exception {
WebView view = new WebView();
WebEngine engine = view.getEngine();
BorderPane root = new BorderPane(view);
TextField addressBar = new TextField("http://lingkang.top");
addressBar.setOnAction(event -> engine.load(addressBar.getText()));
root.setTop(addressBar);
engine.locationProperty().addListener((observable, oldValue, newValue) ->
addressBar.setText(newValue));
stage.setTitle("JavaFX WebView");
stage.setScene(new Scene(root, 800, 600));
stage.show();
engine.load(addressBar.getText());
}
public static void main(String[] args) {
launch(args);
}
}
更多API可以查看 WebEngine 的源码
|