Link to home
Start Free TrialLog in
Avatar of azcalv408
azcalv408

asked on

how do I add colors to strings

Hi,

    I'm new to Java. Can someone tell me how I can change a string to different colors ? Thanks!
    ex:   String s = "Print this line in red";
Avatar of Nick_72
Nick_72

It's not the actual string that has the color property. It's the container in which you present the string. Where are you going to show it?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of azcalv408

ASKER

i want to show it within a Jpanel. thanks
Add the JEditorPane to the JPanel
Or add a JLabel to the JPanel:

JLabel label = new JLabel();
JPanel.add(label);
label.setForeground(Color.RED);
label.setText(theString);
8-)
Almost all JAVA SWING controls (labels, buttons ...) can display HTML texts.
;JOOP!