Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX/Swing加载网页问题_Java_Swing_Javafx - Fatal编程技术网

JavaFX/Swing加载网页问题

JavaFX/Swing加载网页问题,java,swing,javafx,Java,Swing,Javafx,我正在创建一个应用程序,在应用程序中我有三个选项卡,一个是“新闻”选项卡,我只想加载一个网页 到目前为止,我的代码是: import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javafx.scene.web.WebView; import javafx.scene.layout.BorderPane; public class Brow

我正在创建一个应用程序,在应用程序中我有三个选项卡,一个是“新闻”选项卡,我只想加载一个网页

到目前为止,我的代码是:

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebView;

import javafx.scene.layout.BorderPane;

public class BrowserPane extends JFXPanel{
    public BrowserPane() {
        final BrowserPane _this = this;
        Platform.runLater(new Runnable() {
            @Override
            public void run() {

              BorderPane borderPane = new BorderPane();
              WebView webComponent = new WebView();
              System.out.println("Loading URL!");
              webComponent.getEngine().load("http://www.google.com.au/");

              borderPane.setCenter(webComponent);
              Scene scene = new Scene(borderPane,450,450);
              _this.setScene(scene);
            }
        });
    }
}
这样调用:

contentArea.removeAll();
contentArea.revalidate();
contentArea.repaint();

newsPane = new BrowserPane();
newsPane.setBounds(0, 0, 1194, 593);
contentArea.add(newsPane);

contentArea.revalidate();
contentArea.repaint();
现在这很好…第一次单击选项卡时。但是如果您想稍后返回到选项卡。它似乎无法呈现网页。我想这可能是我每次单击选项卡时重新绘制
contentArea
的方式


注意:我使用的是
JTabPanel
选项卡只是
JButtons
,它们的样式是我喜欢的,可以调用各种功能。

为什么每次切换选项卡时都要创建一个WebView、BorderPane和场景?您可以创建它们一次,并在用户每次切换选项卡或希望加载新URL时加载URL。我将如何实现这一点?我认为最好删除不用于保存内存的元素。是否有一个特定的要求将Swing作为依赖项引入?该应用程序使用Swing for GUI JFXPanel只是因为我需要HTML5支持,从我的阅读来看,这是最好的方法(无需花钱)