2011-06-14 124 views
1

我有一个问题。我需要知道,如果可以在JEditorPane(我在http://java-sl.com/JEditorPaneTables.html找到一个示例)插入表而不使用HTML并使用列和行跨越单元格。总之,我需要插入一个表是这样的:JTextPane中的表格和单元格跨越(单元合并)

 
+-------+--------+-------+ 
| first | second | third | 
+-------+--------+-------+ 
| c1 | col. spanning | 
+-------+--------+-------+ 
| c2 |  | c3 | 
+-------+ row s. +-------+ 
| c4 |  | c5 | 
+-------+--------+-------+ 

我试图谷歌,但我无处发现,我所期待的。跨越细胞的问题可能并不常见。

+0

什么是防止使用HTML的一个? – jzd 2011-06-14 12:17:14

+0

根据文档,JEditorPane中的HTML仅限于HTML 3.2。但我不需要显示现有的表,但在JEditorPane中创建新的表。在演示中,我可以添加行和列,但我甚至需要合并单元格。 – 2011-06-14 12:40:12

回答

3

JUst使用HTMLEditorKit并用行和列间距插入所需的tabel。 您可以使用该方法

public void insertHTML(HTMLDocument doc, int offset, String html, 
       int popDepth, int pushDepth, 
       HTML.Tag insertTag) 

,或者你可以得到HTMLDocument的和使用的

public void insertAfterStart(Element elem, String htmlText) 
public void insertBeforeEnd(Element elem, String htmlText) 
public void insertBeforeStart(Element elem, String htmlText) 
public void insertAfterEnd(Element elem, String htmlText) 
public void setOuterHTML(Element elem, String htmlText) 
public void setInnerHTML(Element elem, String htmlText) 
+0

好的,谢谢。我可以只使用HTML部分仅用于表格,或者当我使用HTMLEditorKit时,我必须使用HTML作为整个文档? – 2011-06-15 05:09:47