开发者

Code/text folding in SWING

I'm looking for a way to provide 'text folding' capabilities to a swing JTextArea or JTextPane

More specifically, I want to add a block of data in a text component and I want the component to display only some header line. Then the user can unfold the block by clicking some icon. This is just like the code folding feature in m开发者_开发技巧ost IDE.

I've found ->some sample code<- after some thorough search, but the mechanisms used here are quite obscure to me and it stops working when I try to remove text from the document.

Maybe using XML as input could be a lead ?


This one how to add collapsible area http://java-sl.com/collapse_area.html

This one how to represent XML http://java-sl.com/xml_editor_kit.html


I would start by looking at the NetBeans API: http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-fold/overview-summary.html

If you were to do it yourself, you'd need to provide a Document implementation that makes the JTextComponent think that pieces are being added or removed, then attach click events that tell the document to update itself. A lot of work.

Visually, it may also be better to use JEditorPane, but that's probably more work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜