• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to prevent the user of changing specific text in jtextpane?

 
cluny abramson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i want to implement a code editor using the jtextpane.
some of the code displayed in it is auto generated and some is the user's code.
i need a way to prevent the user of changing the auto generated code part.
is there special tags, chars that i can set in the protected code that the jtextpane knows about and can disable editing for this part?
are there other options to implement this?

how the answer is out there... :-)

best wishes,
Cluny
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at javax.swing.text.DocumentFilter. You will have to keep track of which offsets are allowed to be edited and which are not, but if you know that then DocumentFilter can allow or ignore user edits.
 
cluny abramson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brian,
10'x for the answer however, i don't know exactly the location of the protected text.
i need this implementation for a new workspace i develop. the idea is to build a code editor (lets say foe example perl or java editor). some of the code is automatically generated at the begining of some proccess and the user can add his own cod and extend it.
the only thing i need is to protect the auto generated code from being change by the user but i cant't keep track of it's location as the user may insert his own coda and change the file structure.

Is there any solution using some special tags that the jtextpane (or maybe other component) know to refer as read only? in that case i can wrap the auto generated code with this tags...

hope i explained my self enough :-)

Cluny
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that it would be easiest for you to insert some kind of tag, but JTextPane doesn't support anything like that.

I suppose you could implement a DocumentFilter that looks for tags that have been inserted, but if you know where to insert the tags then it seems to me you could also keep track of the locations without inserting them.
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cluny abramson wrote:10'x for the answer


Cluny, please UseRealWords <- link
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Protected Text Component might offer you a solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!