开发者

Tables in JTextPane and cell spanning (cell merging)

开发者 https://www.devze.com 2023-03-12 14:41 出处:网络
I have a question. I need to know, if it is possible to insert table in JEditorPane (I have found an example at http://java-sl.com/JEditorPaneTables.html) without using HTML and to use the column and

I have a question. I need to know, if it is possible to insert table in JEditorPane (I have found an example at http://java-sl.com/JEditorPaneTables.html) without using HTML and to use the column and row spanning cells.开发者_如何学Python In short I need to insert a table like this:

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

I tried to google it, but I nowhere have found, what I am looking for. The question of the spanning cells is perhaps not so common.


JUst Use HTMLEditorKit and insert desired tabel with row and col spans. You can use the method

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

or you can get HTMLDocument and use one of the

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号