Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTextPane immutable text blocks

I've been creating something like text editor for a while and noticed one interesting feature in NetBeans: when creating Java Application from a template (for example, "Desktop Application"), it creates immutable blocks of code (they are present for viewing but they can not be modified directly).

This shot should make all that text above clear:

enter image description here

So, the question is: how to implement such a feature using JTextPane?

like image 211
shybovycha Avatar asked Nov 15 '22 02:11

shybovycha


1 Answers

You must create a class implementing the javax.swing.text.DocumentFilter used by your editor pane for the unchanged text. For the highlighting I suppose you will have to use a javax.swing.text.Highlighter.

like image 180
Timmo Avatar answered Dec 16 '22 19:12

Timmo