Solved

How to change the color of a String

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

630 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