• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How to paint a string in red color

 
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.
 
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.
 
Marshal
Posts: 71636
312
  • 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.
 
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??
 
Campbell Ritchie
Marshal
Posts: 71636
312
  • 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
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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
Marshal
Posts: 71636
312
  • 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.
 
I was her plaything! And so was this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic