当我在浏览器中运行项目时,JavaFX Webview显示空白页

时间:2018-10-09 04:41:13

标签: javafx

我正在尝试将自己的JavaFX Web浏览器运行到chrome,Internet Explorer,Firefox等浏览器中。当我在自己的浏览器中加载URL时显示空白页。

我遵循了代码

package web_browser;



public class Web_Browser extends Application {

    TabPane root;
    @Override
    public void start(Stage stage) {


        WebView browser = new WebView();

        Tab browserTab = new Tab("New Tab", browser);
        Tab addTab = new Tab("+", null);
        addTab.setClosable(false);        
        addTab.setOnSelectionChanged(new EventHandler<Event>() {
            @Override
            public void handle(Event event) {
                addNewTab();
            }
        });
        root = new TabPane(browserTab, addTab);
        Scene scene = new Scene(root, 500, 200);
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent t) {
                Platform.exit();
                System.exit(0);
            }
        });
        stage.setScene(scene);
        stage.setTitle("Browser");
        Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();

        stage.setX(primaryScreenBounds.getMinX());
        stage.setY(primaryScreenBounds.getMinY());
        stage.setWidth(primaryScreenBounds.getWidth());
        stage.setHeight(primaryScreenBounds.getHeight());
        stage.show();

    }
      final void addNewTab() {

            WebView browser = new WebView();
            Tab browserTab = new Tab("New Tab", browser);
            root.getTabs().add(root.getTabs().size() - 1, browserTab);
            root.getSelectionModel().select(browserTab);
            browser.getEngine().load("http://www.google.com");
        }


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

当我作为独立应用程序运行时,它工作正常。

0 个答案:

没有答案