wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes color Java text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "color Java text" Watch "color Java text" New topic
Author

color Java text

sara rod
Greenhorn

Joined: Dec 07, 2009
Posts: 23
hi,
I have to show text as java text. I mean, to open file in an editor pane and to color the special words (like, highlight the key words (import, private, etc.) with the same color...)
as a result I want to show the file as it is ahown in other editors of java(eclipse, netBeans, etc..)
Does anybody know code that do this thing?
It will be great if someone know and can give it to me.
thank you all,
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423


You could convert your text into html and use this:


sara rod
Greenhorn

Joined: Dec 07, 2009
Posts: 23
Hi!

this is how to color any text.

the question is how do i know its a java text? how can i know it is public / private - to color it in one color, how do i know its a comment - to color it in a different color etc.

thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18885
    
    8

You mean like there's different colours in the code examples posted here? You need some code which tokenizes and parses a string as if it were Java. That code would have to understand the basic syntax of Java for a start.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
the question is how do i know its a java text? how can i know it is public / private - to color it in one color, how do i know its a comment - to color it in a different color etc.


Well, its not easy. You need to parse the text and reset the attributes every time the text is changed.

You can search the web using "syntax highlighting" and you might find some suggestions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: color Java text