Solved

How to change the color of a String

Posted on 2003-11-09
4
296 Views
Last Modified: 2010-03-31
I made a String and I want to show it in a JOptionPane().  But I don't know how to change the color of that String (or SrtingBuffer)
0
Comment
Question by:Katze
4 Comments
 
LVL 15

Accepted Solution

by:
jimmack earned 75 total points
ID: 9711445
You could put it inside a JLabel.  Then you can include HTML.

JLabel coloredString = new JLabel("<HTML><BODY><FONT COLOR='#FF0000'>" + myString + "</FONT></BODY></HTML>");
0
 
LVL 1

Expert Comment

by:allelopath
ID: 9711628
You could also make it a borderless button and set the foreground color:

  String myString = new String("whatever");
  JButton myButton = new JButton(myString);
  myButton.setBorderPainted(false);
  myButton.setForeground(Color.black);
 
0
 
LVL 4

Assisted Solution

by:vk33
vk33 earned 50 total points
ID: 9712640
Hi! You can set foreground for ANY JComponent. So, you can set foreground for your JLabel:

JLabel label = new JLabel("Hello!");
label.setForeground (Color.RED);
JOptionPane.showMessageDialog(null, label);

Good luck!
0
 

Author Comment

by:Katze
ID: 9718136
Thanks to all of you!!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now