• Post Reply Bookmark Topic Watch Topic
  • New Topic

create a read-only string segment that acts like a character in a textarea  RSS feed

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to create a textarea that has segments of text that act like a character. By this I mean the following:
- the whole string section cannot be edited
- if the first or last characters are deleted, the whole thing is deleted
- the cursor should jump across the whole string as if it were a single character
e.g.
[Number of Fields] * 32 + 5
where the [Number of Fields] is a segment of text that cannot be edited and has the above behaviour (the rest of the string acts like normal)
I know this sounds like a lot but I'm trying to achieve the same sort of behaviour found in Microsoft Word for autotext (like toc, page numbers or date stamps).
Is this possible (an of it)? If so, any help would be greatly appreciated.
Thanks in advance,
Steve
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this would work :
add a keyListener to the textArea. Everytime a key is pressed, extract the key tht was pressed and act accordingly (e.g. if key is '>' and character to right carat is your special field, move carat to end of field).

hope this helps,
T.
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
I've had a look at the JTextPane from what you mentioned. There's a good article I found that should start me off pretty well:
http://developer.java.sun.com/developer/TechTips/1999/tt1005.html#tip1
I should be able to take it from here.
Cheers,
Steve
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!