Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to paint a string in red color

 
sujai chellappa
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes! Of course! It is posible!
Soon someone will help you with your problem.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49770
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sujai chellappa
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Campbell Ritchie
Sheriff
Pie
Posts: 49770
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you are right, Maneesh, that I misunderstood the question. Anyway, we seem to have to correct answers.
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even I was thinking from the GUI point of view initially. Later on the OP mentioned console.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49770
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic