【发布时间】:2011-04-25 11:27:07
【问题描述】:
我正在尝试在我的 HTML 中包含链接样式表的 Java 应用程序中显示 HTML。
我正在使用来自 Java 的 XSLT 将我的 XML 转换为 HTML。我想包含一个样式表,以便我可以轻松地设置 html 输出的样式。但是样式表被忽略,html正常输出。
为此,我使用了 JEditorPane 和 HTMLEditorKit。我在Dev Daily 上找到了一些示例代码来执行此操作。
我的样式表位于本地硬盘上,我想知道是否有人知道我可以如何使用它?
我有以下代码:
JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setEditable( false );
HTMLEditorKit kit = new HTMLEditorKit();
jEditorPane.setEditorKit(kit);
try {
kit.getStyleSheet().importStyleSheet( new URL( "file://D:\\mycssfile.css" ) );
} catch( MalformedURLException ex ) {
}
Document doc = kit.createDefaultDocument();
jEditorPane.setDocument(doc);
jEditorPane.setText(html);
在我的 xsl html 输出中,css 使用以下内容链接 - 我得到相同的结果,包括或排除它:
<link rel="stylesheet" type="text/css" href="mycss.css" />
有什么想法吗?
干杯,
安德斯
【问题讨论】:
-
我认为 HTMLEditorKit 对 CSS 的支持相当差,这可能是问题