Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Code folding or collapsing using JEditorPane and Document

843804Nov 24 2004 — edited Nov 25 2004
Hi,

I am interested to hear of any suggestions or recommendations for how to implement text editor code folding/collapsing functionality where a block of code can be 'folded' down to a single line in an editor for ease of navigation, etc.

Perhaps obviously, I would prefer to divorce the model from the view so that the complete text is always present in the Document, just viewed differently depending on how blocks have been folded.

I have tried to do this by writing custom views for my document such that a request to paint a child line of a folded paragraph is mapped to a zero size BoxView, and all subsequent lines are painted higher in the doc to compensate for the missing lines above them. This almost works but there seem to be issues with both repainting and painting when the text in the doc is selected (lines disappearing completely or partially redrawing).

Does anyone have suggestions for other approaches to try? As I said earlier I would MUCH prefer to maintain the document ''model" intact and manipulate the view of it somehow, but would be glad to hear of any suggestions.

Thanks,

Chris
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 23 2004
Added on Nov 24 2004
1 comment
190 views