Solved

How to change the color of a String

Posted on 2003-11-09
4
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

756 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