简体   繁体   English

在Swing应用程序中渲染html

[英]Render html in Swing application

I have a swing application that sends commands to server and receives result in XML format. 我有一个swing应用程序,它向服务器发送命令并以XML格式接收结果。 I need to transform this into HTML via XSLT and then display result HTML on the panel. 我需要通过XSLT将其转换为HTML,然后在面板上显示结果HTML。 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. 问题是能够显示HTML的唯一Swing组件 - JEditorPane - 将URL或javax.swing.text.StyledDocument作为源。 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. 带URL的选项对我不起作用,因为我必须首先将html保存为文件系统中的文件,我想避免这种情况。

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. 所以我在XSL转换的内存结果和javax.swing.text.StyledDocument之间存在差距,它可以由JEditorPane或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)? 或者是否有任何其他Swing解决方案来显示来自某些内存源(DOM或String或其他)的HTML?

Thank you in advance for help. 提前感谢您的帮助。

Is there a reason that JEditorPane.setText() does not work for you? 是否有理由说JEditorPane.setText()不适合你?

I use JEditorPane all the time and I've never pulled the displayed data from a file or URL. 我一直使用JEditorPane,我从来没有从文件或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>" );

那么JeditorPane.setText()呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM