开发者

Code/text folding in SWING

开发者 https://www.devze.com 2023-02-24 10:13 出处:网络
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 disp

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

精彩评论

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