This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes how to paint a particular word in a string ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "how to paint a particular word in a string ?" Watch "how to paint a particular word in a string ?" New topic
Author

how to paint a particular word in a string ?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 675

i m making a text editor in that when ever user type a certain java keyword like void just that word will be appeared as blue and rest other work should be red
i m using keylistener but unfortunately my logic is notworking here
what is happening here is when i write some thing like
class void then i press enter then the color of the text changes to red and from then on the entire text is written in red color
same is the case with blue ....so please can you tell me where i m wrong and what is key thing in this which i m missing ?



The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Check out javax.swing.text.Highlighter. In short:
- retrieve the text field's current highlighter.
- if there is none (null is returned) create one (DefaultHighlighter) and set it.
- get a Highlighter.HighlightPainter (usually DefaultHighlighter.DefaultHighlightPainter).
- add a highligh to the Highlighter.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 675

Rob Spoor wrote:Check out javax.swing.text.Highlighter. In short:
- retrieve the text field's current highlighter.
- if there is none (null is returned) create one (DefaultHighlighter) and set it.
- get a Highlighter.HighlightPainter (usually DefaultHighlighter.DefaultHighlightPainter).
- add a highligh to the Highlighter.


i have searched in the google but all examples are quite complex so this is my code can you give a example code to color a particular text like "void"
so that i can learned it in a simple way
please
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Moving to our user interface forum.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how to paint a particular word in a string ?
 
Similar Threads
enums
Changing Color of a selectedtext in TextArea
how to color a particular word in jtextpane ?
reverse the text file and write
Key Words Invocation in Java