permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes How to paint a string in red color Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to paint a string in red color" Watch "How to paint a string in red color" New topic
Author

How to paint a string in red color

sujai chellappa
Greenhorn

Joined: May 15, 2009
Posts: 9
Hi all,
Is there any way to print a String in Red or any other color.
Is it possible in java??

Sujai.
Sergio Campos J.
Ranch Hand

Joined: Jun 01, 2009
Posts: 53
Yes! Of course! It is posible!
Soon someone will help you with your problem.


"There are times when the easy things should be quick and easy" [...] "and worry about the theory later" -Fred Hamilton-
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39103
    
  23
You would use the setForeground() method of the Component you are painting on. Probably called inside the paintComponent() method.

That sort of thing is usually discussed on the Swing forum, so I shall move you there.
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Campbell, while your solution to the question was how to do this in Swing I'm not sure the original poster meant "in a swing app". Maybe they were just using the word paint loosely?

SCJA
~Currently preparing for SCJP6
sujai chellappa
Greenhorn

Joined: May 15, 2009
Posts: 9
Mine was a simple solution as my text were inside an output text.
But is it possible to print in red on console??
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

Maybe this will help
http://en.wikipedia.org/wiki/ANSI_escape_code


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39103
    
  23
Maybe you are right, Maneesh, that I misunderstood the question. Anyway, we seem to have to correct answers.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

Even I was thinking from the GUI point of view initially. Later on the OP mentioned console.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39103
    
  23
You did well to pick up what the original poster meant, Maneesh.

There has been discussion, in a few threads, about the console escape sequences here before; if you search you will probably find useful information.
 
GeeCON Prague 2014
 
subject: How to paint a string in red color