在JTextPane的底部显示html文本

时间:2013-04-05 06:32:25

标签: html jtextpane

我一直在尝试使用html在JTextPane区域的底部显示一些文本。由于它不支持样式,我使用以下代码:

<!-- saved from url=(0040)file:///C:/Users/tusim/Desktop/test.html -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
table { font-family:"tahoma"; font-size:11; width: 100%
}
td, th {
background-color: white}
.header {font-weight:bold;}
.record-first {font-weight:bold; min-width: 130px;}
</style>
</head>
<body><table border="0" cellpadding="2" cellspacing="1" height="95%"><tbody><tr height="95%"><td width="32%" height="95%" valign="top"><div style="background-color: black; width: 100%;"><table border="0" cellpadding="2" cellspacing="1">
<tbody><tr class="header"> <td align="center">Col 1</td> </tr><tr><td>Val 1</td></tr></tbody></table></div></td><td></td><td width="32%" valign="top"><div style="background-color: black; width: 100%;"><table border="0" cellpadding="2" cellspacing="1">
<tbody><tr class="header"> <td align="center">Col 2</td> </tr><tr><td>Val 2</td></tr></tbody></table></div></td><td></td><td width="32%" valign="top"><div style="background-color: black; width: 100%;"><table border="0" cellpadding="2" cellspacing="1">
<tbody><tr class="header"> <td align="center">Col 3</td> </tr><tr><td>Val 3</td></tr></tbody></table></div></td></tr><tr height="5%" valign="bottom"><td colspan="5" valign="bottom">some text</td></tr></tbody></table></body></html>

但是它虽然在浏览器上运行,但不在JTextPane中。有人可以帮帮我。

提前感谢...

1 个答案:

答案 0 :(得分:1)

您确定JTextPane支持表吗?

使用JEditorPane而不是使用JTextPane。 它也可以渲染HTML,虽然它有一些叫做的东西  HTMLEditorKit,可以解析HTML文档。

以下是一个例子:

HTMLEditorKit kit = new HTMLEditorKit(); // Creates an instance
editorPane.setEditorKit(kit); // Sets the Editor Kit