0
我正在开发一个项目。在那个项目中,我必须在Java FX GUI中显示一个网页。但它不起作用。它只显示一个白色的窗口。我的网路连线开启。WebView在JavaFX中不起作用
任何人都可以提出建议我可以做什么来显示我的JavaFX GUI中的网页?
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
stage.setTitle("HTML");
stage.setWidth(500);
stage.setHeight(500);
Scene scene = new Scene(new Group());
VBox root = new VBox();
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
Hyperlink hpl = new Hyperlink("google.com");
hpl.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
webEngine.load("http://google.com");
}
});
root.getChildren().addAll(hpl,browser);
scene.setRoot(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
你的代码是正确的。确保在项目中运行正确的Main类,检查IDE设置,尝试Clean-Build您的项目。 –
确保您拥有最新版本的Java jdk – Sedrick
我使用jdk 8.0,那么,有什么问题? –