Code/text folding in SWING

…衆ロ難τιáo~ 提交于 2019-12-10 15:46:01

问题


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 most 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 ?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5663335/code-text-folding-in-swing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!