This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
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
 
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!