2013-04-05 44 views
0

我一直试图用html显示一些文本在JTextPane区域的底部。因为它不支持风格,我用下面的代码:在JTextPane底部显示html文本

<!-- 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

你确定的JTextPane支持表格?

不使用JTextPane,而是使用JEditorPane。 它也可以呈现HTML,虽然它有一些名为 HTMLEditorKit,它可以解析HTML文档。

下面是一个例子:

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

感谢您的提示。 但HTMLEditorKit似乎无法正常工作。似乎高度参数不支持。 – KTB 2013-04-09 09:18:33

+0

哦,好的。对不起,它没有解决。 – user2228462 2013-04-09 21:37:32