在 Swing 应用程序中呈现 html [英] Render html in Swing application

查看:29
本文介绍了在 Swing 应用程序中呈现 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Swing 应用程序,它向服务器发送命令并接收 XML 格式的结果.我需要通过 XSLT 将其转换为 HTML,然后在面板上显示结果 HTML.问题是唯一能够显示 HTML 的 Swing 组件 - JEditorPane - 将 URL 或 javax.swing.text.StyledDocument 作为源.带有 URL 的选项对我不起作用,因为我必须首先将我的 html 保存为文件系统上的文件,我想避免这种情况.

I have a swing application that sends commands to server and receives result in XML format. I need to transform this into HTML via XSLT and then display result HTML on the panel. The problem is that the only Swing component which is able to display HTML - JEditorPane - takes either URL or javax.swing.text.StyledDocument as a source. Option with URL doesn't work for me because I have to save my html as a file on the file system first and I'd like to avoid this.

所以我在 XSL 转换的内存结果和 javax.swing.text.StyledDocument 之间存在差距,可以通过 JEditorPane 或 JTextPane 呈现.

So I have a gap between in-memory result of XSL transformation and javax.swing.text.StyledDocument, which can be rendered by JEditorPane or JTextPane.

如何将一个转换为另一个?或者是否有任何其他 Swing 解决方案来显示来自某些内存源(DOM 或字符串或其他)的 HTML?

How to transform one to another? Or are there any other Swing solutions to display HTML from some in-memory source(DOM or String or whatever)?

预先感谢您的帮助.

推荐答案

JEditorPane.setText() 对您不起作用的原因是什么?

Is there a reason that JEditorPane.setText() does not work for you?

我一直使用 JEditorPane,但从未从文件或 URL 中提取显示的数据.所以这是可能的.只需要弄清楚为什么它不适合你.

I use JEditorPane all the time and I've never pulled the displayed data from a file or URL. So it is possible. Just need to figure out why it's not working for you.

具体来说:

editor.setContentType( "text/html" );    
editor.setText( "<html><body>Hello, world</body></html>" );

这篇关于在 Swing 应用程序中呈现 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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