使用此代码和硬编码的网址,网址中的图形无法加载。我尝试禁用我的防火墙并在JDK 9下使用Netbeans 9的预发布版本运行它。没有运气。 WebSocket测试说WebSocket工作正常(url在代码中注释掉)。任何想法有什么不对或我应该检查什么?无论测试结果如何,我的猜测都与WebSocket有关。我使用Netbeans 8.2和jdk1.8.0_144。
//
// Code from https://stackoverflow.com/questions/42297864/javafx-webview-in-java-project
//
public class FXWebViewInSwing {
private JFXPanel jfxPanel;
public void createAndShowWindow() {
JFrame frame = new JFrame();
JButton quit = new JButton("Quit");
quit.addActionListener(event -> System.exit(0));
jfxPanel = new JFXPanel();
Platform.runLater(this::createJFXContent);
JPanel buttonPanel = new JPanel();
buttonPanel.add(quit);
frame.add(BorderLayout.CENTER, jfxPanel);
frame.add(BorderLayout.SOUTH, buttonPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1024, 576);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void createJFXContent() {
WebView webView = new WebView();
webView.getEngine().load("https://www.tradingview.com/chart/bKsZf5LY/");
// webView.getEngine().load("https://websocket.org/echo.html");
Scene scene = new Scene(webView);
jfxPanel.setScene(scene);
}
public static void main(String[] args) {
FXWebViewInSwing swingApp = new FXWebViewInSwing();
SwingUtilities.invokeLater(swingApp::createAndShowWindow);
}
}