• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

cluny abramson wrote:10'x for the answer



Cluny, please UseRealWords <- link
 
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Protected Text Component might offer you a solution.
reply
    Bookmark Topic Watch Topic
  • New Topic