0

我一直在尝试使用 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 中。有人可以帮帮我吗。

提前致谢...

4

1 回答 1

1

你确定 JTextPane 支持表格吗?

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

这是一个例子:

HTMLEditorKit kit = new HTMLEditorKit(); // Creates an instance
editorPane.setEditorKit(kit); // Sets the Editor Kit
于 2013-04-08T00:00:26.287 回答