有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Swing应用程序上的java JavaFX Webview未加载在标准web浏览器上正确加载的内容

我有一个Java/Swing应用程序,通过它我想从这个URL加载和显示网页:http://funsoft.systempartners.biz:8042/stone-webviewer/index.html?study=2.16.840.1.113669.632.20.1211.1000035777

此URL仅包含测试内容。JavaFX Webview组件试图无限期地加载它,同时在标准web浏览器上立即加载

许多版本的JavaFX已经过测试,但结果相似,最新的版本是16

我在下面附上了我正在使用的代码。关于内容无法成功处理的原因有何建议?提前感谢

谢谢

查尔斯

我的代码:

import java.awt.Toolkit;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.web.WebView;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.swing.JButton;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.SwingUtilities;

/**
 *
 * @author Charles Waweru <cwaweru@systempartners,biz>
 */
public class PacsViewerMain extends javax.swing.JFrame {

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("pACS Viewer");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 833, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 406, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
//        SwingUtilities.invokeLater(() -> {
            PacsViewerMain jFrameTest = new PacsViewerMain();
            jFrameTest.setDefaultCloseOperation(EXIT_ON_CLOSE);
            jFrameTest.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
            JFXPanel jfxPanel = new JFXPanel();
            jFrameTest.add(jfxPanel);

            Platform.runLater(() -> {
//                jFrameTest.setMaximumSize(Toolkit.getDefaultToolkit().getScreenSize());
                jFrameTest.setVisible(true);
                WebView webView = new WebView();
                jfxPanel.setScene(new Scene(webView));
                // Create a trust manager that does not validate certificate chains
                TrustManager[] trustAllCerts = new TrustManager[]{
                    new X509TrustManager() {
                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                            return null;
                        }

                        public void checkClientTrusted(
                                java.security.cert.X509Certificate[] certs, String authType) {
                        }

                        public void checkServerTrusted(
                                java.security.cert.X509Certificate[] certs, String authType) {
                        }
                    }
                };

// Install the all-trusting trust manager
                try {
                    SSLContext sc = SSLContext.getInstance("SSL");
                    sc.init(null, trustAllCerts, new java.security.SecureRandom());
                    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
                } catch (GeneralSecurityException e) {
                }
                webView.getEngine().setJavaScriptEnabled(true);
                webView.getEngine().getCreatePopupHandler(); //setOnAlert(null);
                webView.getEngine().load("http://funsoft.systempartners.biz:8042/stone-webviewer/index.html?study=2.16.840.1.113669.632.20.1211.1000035777");
            });
//        });
    }

    private Scene createScene() {
        Group root = new Group();
        Scene scene = new Scene(root, Color.ALICEBLUE);
        Text text = new Text();

        text.setX(40);
        text.setY(100);
        text.setFont(new Font(25));
        text.setText("Welcome JavaFX!");

        root.getChildren().add(text);

        return (scene);
    }
    // Variables declaration - do not modify                     
    // End of variables declaration                   
}


共 (0) 个答案