【问题标题】:Replacement for context.showDocument() in JavaWebStart applicationJavaWebStart 应用程序中 context.showDocument() 的替换
【发布时间】:2018-12-09 16:12:51
【问题描述】:

我正在将浏览器小程序中的旧旧应用程序迁移到通过 JNLP 启动的基于 JFrame 的 JWS 应用程序。
在小程序基础应用程序中,我使用context.showDocument() 打开任意大小的浏览器窗口,并配置为不显示栏(菜单栏、状态栏、滚动条)和不可调整大小(通过 Javascript ())。

但现在这不起作用。
我可以在 JavaWebStart/JNLP 应用程序中解决这个问题吗?
我需要打开一个 HTML 页面并在一个没有通常栏的大小窗口中显示竞争。 当我现在使用 showDocument() 表单 JNLP basicServices 时,我不能这样做(没有 JavaScript)。

【问题讨论】:

    标签: java browser java-web-start jnlp


    【解决方案1】:

    通常应该可以在 javafx webview 中预览 html 文件,就像使用普通的 java 应用程序一样。我不确定此操作所需的 jnlp 权限:

    private void previewHtml(String url) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame fr = new JFrame();
                final JFXPanel fxPanel = new JFXPanel();
                fr.add(fxPanel);
                fr.setSize(1000, 600);
                fr.setVisible(true);
    
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        final Group  rootGroup  =  new  Group();
                        final Scene scene = new Scene(rootGroup, 1000, 600, Color.WHITE);        
                        final WebView webView = WebViewBuilder.create().prefHeight(600).prefWidth(1000).build();
                        webView.getEngine().load(url);
                        rootGroup.getChildren().add(webView);
                        fxPanel.setScene(scene);
                        fxPanel.show();
                    }
                });                
            }
        });
    
    }
    
    
    //You can add the following code to a button actionListener:
    
    //prevew html from classpath:
    previewHtml(getClass().getResource("/classpath-file.html").toExternalForm());
    
    //prevew html from url:
    previewHtml("https://stackoverflow.com/");
    

    【讨论】:

    • 我正在使用 swing(JFrame 等)将它与 javafx webview 混合是一个好主意吗?
    • 第二个问题:为什么我们这里有两次调用/运行后的示例:java.awt.EventQueue.invokeLater & Platform.runLater;这是什么原因?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    相关资源
    最近更新 更多