2013-04-05 43 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