How to set string color?
hi,
How do i set the color of a string without not having to do anything like this.
publicvoid paintComponent(Graphics g)
{
g.setColor(Color.RED);
g.drawString("Just a test");
It would be easier if i could do something like this:
String s ="just a test";
//s.setColor(Color.RED);
//or Color.setColor(s);
//I'm just brainstorming :)
Greetz Daan
[654 byte] By [
D-a-a-na] at [2007-11-27 3:35:33]

Color is not a String property. You will have to continue to do things like the code you posted or use components that support styled attributes like JEditorPane or JTextPane.
Tutoiral: http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html
Message was edited by:
DrLaszloJamf
Thx for all responses,
I'm trying to return a string with different colors in it;
//I make a string
String s = "";
//a condition
if (tdr == 0)
{
s += "Enemy missed!\n";// >>>>This should look green
}
//and at some other point:
if (generate.nextInt(101) > 75)
{
s +=("Your armor is reduced with 1. \n");//>>>This should look red.
}
//and at the end:
return s;
//s is afterwards displayed in a JTextPane
Greetz Daan