JavaFX Swing浏览器非常慢 [英] JavaFX Swing Browser Very Slow

查看:389
本文介绍了JavaFX Swing浏览器非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调用类似JFrame的东西来使用O-Auth对用户进行身份验证。我实现了所有后台验证需求,使用默认浏览调用进行测试:

I'm trying to call something like a JFrame to authenticate a user using O-Auth. I implemented all background need for authentication, tested with default browing calling:

Desktop.getDesktop().browse(java.net.URI.create(url));

使用默认浏览器,每个人都可以正常工作。
然后我尝试创建我的owh webview以在我的应用程序中调用。环顾四周,我找到了oracle实现 Oracle JavaFX + Swing示例。 Oracle实现可行,但速度很慢。我在eclipse中复制并粘贴代码并在java8下运行该类。

Using the default browser everythings work as it shoud. Then I tried to create my owh webview to call within my application. Looking around I found the oracle implementation Oracle JavaFX+Swing example. The Oracle implementation works but is very slow. I copied and pasted the code in eclipse and run the class under java8.

当我放弃Oracle示例时,我发现了这个:
哪个更快并且干净但是当我调用 Application.launch(args); 我的应用程序挂起。

When I was giving up of Oracle example I found this one: which is faster and clean but when I call Application.launch(args); my application hangs.

public class Test extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        StackPane root = new StackPane();

            WebView view = new WebView();
        WebEngine engine = view.getEngine();
        engine.load("http://www.google.com.br/");
        root.getChildren().add(view);

        Scene scene = new Scene(root, 800, 600);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) throws IOException {
        Application.launch(args);

    }
}

如果我可以打电话给 Application.launch(args); 在另一个帖子中就足够了。

If I could callApplication.launch(args); in another thread it shoud be enough.

如何从我的应用程序中调用简单的webView ?

How can I call a simple webView from my application?

推荐答案

看起来性能问题是JavaFX 8u25和JavaFX 8u40的已知问题:

It looks like the performance issue is a known issue with JavaFX 8u25 and JavaFX 8u40:

来自我的测试问题与WebView是在Swing中嵌入运行还是作为独立的JavaFX应用程序无关。如果WebView的宽度小于800像素,则Oracle页面将在大约六秒内完全加载和渲染,如果WebView的宽度超过800像素,则加载将花费超过30秒。此外,广泛的WebView仍然缓慢且无响应,您尝试与其进行交互,使其无法使用。

From my testing the issue is independent of whether the WebView is running embedded in Swing or as a stand-alone JavaFX application. The behavior is that the Oracle page will load and render completely in about six seconds if the width of the WebView is under 800 pixels and will take over thirty seconds to load if the width of the WebView is over 800 pixels. Additionally the wide WebView remains slow and unresponsive which you try to interact with it, making it unusable.

问题是网站内容特定,因为如果您加载 http://www.google.com.br/ 进入大小为1024x768的WebView,无论WebView是Swing包装还是纯JavaFX应用程序都没关系 - 性能看起来相同(完成加载)大约2.5秒)。测试系统是运行OS X 10.9和Java 8u40的Retina Mac。

The issue is site content specific, because if you load http://www.google.com.br/ into a WebView with a size of 1024x768, it doesn't matter if the WebView is Swing wrapped or a pure JavaFX application - performance appears identical (completes loading in about 2.5seconds). Test system was a Retina Mac running OS X 10.9 and Java 8u40.

该问题的目标是为Java 9修复(你可以尝试此处的早期访问版本)。该问题尚未被标记为Java 9已解决,因此可能仍在进行修复工作。

The issue is targeted to be fixed for Java 9 (you can try out early access releases here). The issue has not yet been marked as resolved for Java 9, so there is probably still ongoing work involved to fix it.

作为解决方法,不要让它WebView的大小超过800x600。

As a work-around, don't let the size of your WebView go above 800x600.

我不知道上面是你的确切问题,但可能是。可能看起来好像纯JavaFX应用程序比基于Swing的应用程序表现更好,因为纯JavaFX应用程序在(可能)不同内容上使用较小的WebView窗口。

I do not know that the above is your exact issue, but it probably is. Likely it seemed as though the pure JavaFX application was performing better than the Swing based application because the pure JavaFX application was working with a smaller WebView window on (perhaps) different content.

如果您仍然需要为应用程序加载实际内容(而不是指向oracle或Google网站的内容),请提供 mcve ,会为您的内容产生问题。

If you continue to have issues with the actual content you need to load for your application (as opposed to something which points to oracle or google web sites), then provide a mcve which produces the issue for your content.

如果您的申请是在Swing应用程序中,您应该使用JFXPanel嵌入WebView(如Oracle SimpleSwingBrowser示例代码),而不是尝试从Swing应用程序中启动JavaFX应用程序。如果您的应用程序是JavaFX应用程序,那么就不需要多次启动JavaFX应用程序(并且JavaFX应用程序生命周期规则无论如何都禁止它)。

If your application is a Swing application, then you should use a JFXPanel to embed the WebView (like the Oracle SimpleSwingBrowser sample code) rather than trying to launch a JavaFX application from within a Swing application. If your application is a JavaFX application, then there is no need to launch the JavaFX application more than once (and the JavaFX application lifecycle rules prohibit that anyway).

这篇关于JavaFX Swing浏览器非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆