Code / Text Summary in SWING

I am looking for a way to provide “text folding” features for swing JTextArea or JTextPane

In particular, I want to add a data block to a text component, and I want the component to display only some header line. The user can then expand the block by clicking the icon. This is similar to the code folding feature in most IDEs.

I found -> some sample code <- after some careful searching, but the mechanisms used here are pretty obscure, and this stops working when I try to remove text from a document.

Maybe using XML as input can be leading?

+4
source share
2 answers

This is how to add a folding area http://java-sl.com/collapse_area.html

This way of presenting XML is http://java-sl.com/xml_editor_kit.html

+5
source

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 needed to do this yourself, you need to provide a Document implementation that makes the JTextComponent think that the parts are being added or removed, and then attach click events that indicate that the document is being updated. A lot of work.

Visually, it is better to use JEditorPane , but maybe work more.

0
source

Source: https://habr.com/ru/post/1348089/


All Articles