Solved

How to change the color of a String

Posted on 2003-11-09
4
303 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 50
throw exception 21 58
pagenation logic how it is working in my code 1 54
How to determine if a string is a valid SHA value 7 35
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

837 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