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

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

问题描述

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



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



如何将一个转换成另一个?或者是否还有其他的Swing解决方案可以显示来自某些内存源(DOM或String或其他)的HTML?

预先感谢您的帮助。

解决方案

是否有JEditorPane.setText()不适合您的原因?

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



具体来说:

  editor.setContentType(text / html); 
editor.setText(< html>< body> Hello,world< / body>< / 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.

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.

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)?

Thank you in advance for help.

解决方案

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

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.

To be specific:

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

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

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