(String) font color

hi all.

i have a method that returns a 'String' value

how can i change the color of the value before it returns.

eg.

public String getMesage() {

if not valid return red colored string

else

return blue colored string

}

i'd like to use this on a swing component jtextfield.

but i dont want to use jtextfields.setForeground(Color);

[401 byte] By [kurapikatsa] at [2007-10-2 14:25:23]
# 1
Color is not a String property. You can't return a color with a string. What you can do is set a boolean and return that. Then, test the boolean and use the result to select a color.
ChrisLesliea at 2007-7-13 12:44:54 > top of Java-index,Java Essentials,New To Java...
# 2

Hi,

the Color of a Label shown in view should be a property of the view. Anything defined inside a model class - a class holding data and working with it, should be unrelated to the view itself. If you need some property defining a state of the model needs to be defined view independent. Only if the Color itself is a businessproperty (the color of a car for example) color can be part of your model.

public class Fax{

public static int PRIORITY_SLOW=0;

public static int PRIORITY_NORMAL=1;

public static int PRIORITY_FAST=2;

private String message;

private String sender;

private String receiver;

// priority is a state of a Fax and can be used to

// change the color in some view - no color is needed here!

private int priority;

}

but

public class Car{

// here a Color can be allowed - but maybe a RGB Value in int or a

// String is a better datatype to hold the value

private Color carColor;

}

So your problem is a OO Design problem - review your classes,

lars.

mezlera at 2007-7-13 12:44:54 > top of Java-index,Java Essentials,New To Java...