在不使用 JEditorPane 的情况下查看 Applet 内的 HTML

发布于 2024-07-11 09:45:42 字数 712 浏览 4 评论 0原文

我有一个小的(500kb)swing 小程序,它使用 JEditorPane 显示非常简单/有限的一组小 HTML 页面,但是这似乎不能 100% 流畅地工作,一些客户会显示一个空白页面,没有任何 java 异常。 该页面在我的机器上运行正常。 我需要一种更可靠的方式来向所有用户显示 HTML 页面。

如果有一个小的+免费类可以代替 JEditorPane 使用,有什么想法 或者是否有一个简单的修复方法可以使其更可靠(非空白)

private JEditorPane m_editorPane = new JTextPane();


    m_editorPane.setEditable( false);

    m_editorPane.setBackground(new Color(239  ,255, 215));
    m_editorPane.setBounds(30,42,520,478 );
    m_editorPane.setDoubleBuffered(true);
    m_editorPane.setBorder(null);

    m_editorPane.registerEditorKitForContentType("text/html", "com.xxxxx.SynchronousHTMLEditorKit");


m_editorPane.setPage(ResourceLoader.getURLforDataFile(param.trim())); 

I have a small (500kb) swing applet that displays very simple/limited set of small HTML page(s) inside it with JEditorPane, however this does not seem to work 100% fluently, some customers get a blank page displayed without any java exceptions. The page works OK from my machine. I need a more reliable way to show HTML page to all our users.

Any ideas if there is a small + free class to use instead of JEditorPane
OR is there an easy fix to make it more reliable (non blank)

private JEditorPane m_editorPane = new JTextPane();


    m_editorPane.setEditable( false);

    m_editorPane.setBackground(new Color(239  ,255, 215));
    m_editorPane.setBounds(30,42,520,478 );
    m_editorPane.setDoubleBuffered(true);
    m_editorPane.setBorder(null);

    m_editorPane.registerEditorKitForContentType("text/html", "com.xxxxx.SynchronousHTMLEditorKit");


m_editorPane.setPage(ResourceLoader.getURLforDataFile(param.trim())); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

太阳男子 2024-07-18 09:45:42

虽然我以前没有使用过,Lobo 是一个支持 Java 的开源 Web 浏览器适用于 HTML 4、Javascript 和 CSS 2。

相比JEditorPane 仅支持 HTML 3.2,看来 Lobo 可能是加载现代网页的更好选择。

Although I haven't used it before, Lobo is an open source web browser for Java with support for HTML 4, Javascript and CSS 2.

Compared to the JEditorPane which only has support of HTML 3.2, it seems like Lobo may be a better bet for loading modern web pages.

很酷不放纵 2024-07-18 09:45:42

AFAIK,JEditorPane 是一个非常原始的 HTML 组件:它被 CSS 迷惑了,对 JS 一无所知。
我怀疑你会发现一个“小+免费”的类做得更好,HTML 解析和显示不是一件简单的事情,在今天更是如此。

也许最好让业内的大人物来处理这个任务,即。 使用 Internet Explorer 或 Mozilla 组件(取决于可用的组件等):JDIC:在 Java 中嵌入 Web 浏览器

AFAIK, JEditorPane is a very primitive HTML component: it is confused by CSS and knows nothing about JS.
I doubt you will find a "small + free" class doing better, HTML parsing and displaying isn't a simple business, even less today.

Perhaps it is better to let the big names in the business to take care of this task, ie. using Internet Explorer or Mozilla components (depending on what is available, etc.): JDIC: Embedding a Web browser in Java.

耶耶耶 2024-07-18 09:45:42

我最近 POC 了几个 java HTML 渲染解决方案。 我们决定使用 JEditorPane 是因为我们确实需要最小化 jar 的大小,并且它内置于 Swing 中。 不过,我遇到的最好的库是Flying Saucer。 它没有任何 js 支持,但它的渲染质量和 api 是一流的,而且它是“免费”(LGLP)、100% Java,并且只有大约 1mb(对我们来说仍然太大,但与其他选项相比很小)。 但是,它只呈现严格的 XHTML(所有属性值都必须加引号,所有标签都必须正确形成),但这可能没问题,具体取决于您的需求(以及 HtmlCleaner 或其他一些此类实用程序可能有助于实现这一目标)。

I've recently POC-ed several java HTML rendering solutions. We decided on JEditorPane because we really need to minimize the size of our jar and it's built into Swing. However, the best library I came across was Flying Saucer. It doesn't have any js support but it's rendering quality and api is top notch, and it's "free" (LGLP), 100% Java, and only about 1mb (still too big for us, but small compared to other options). However, it only renders strict XHTML (all attribute values have to be quoted, all tags properly formed), but that may be OK depending on your needs (and HtmlCleaner or some other such utility may help towards that end).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文