1

How should I do that for this String?

Orb of Deception Range: 880 Cooldown: 7 Cost: 70/75/80/85/90 Mana

I want to have color blue and size 14 for "Orb of Deception", and "Range"/"Cooldown"/"Cost" color black size 12, and the numbers color green and size 10.

It must be contained in one JLabel.

Is this possible?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
DHH
  • 97
  • 6

1 Answers1

2

E.G. (adjust to need)

enter image description here

import java.awt.*;
import javax.swing.*;

class ColoredLabel {

    static String text =
            "<html>"
            + "<head>"
            + "<style type='text/css'>"
            + ".name {"
            + " font-size: 16px;"
            + " color: blue;"
            + "}"
            + ".value {"
            + " font-size: 12px;"
            + " color: green;"
            + "}"
            + "</style>"
            + "</head>"
            + "<body>"
            + "<h1>Orb of Deception</h1>"
            + "<table border=1>"
            + "<tr><td class='name'>Range</td><td class='value'>880</td></tr>"
            + "<tr><td class='name'>Cost</td><td class='value'>70/75/80/85/90 Mana</td></tr>"
            + "<tr><td class='name'>Cooldown</td><td class='value'>7</td></tr>"
            + "</table>"
            + "</body>"
            + "</html>";

    public static void main(String[] args) {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                JOptionPane.showMessageDialog(null, new JLabel(text));
            }
        };
        // Swing GUIs should be created and updated on the EDT
        // http://docs.oracle.com/javase/tutorial/uiswing/concurrency
        SwingUtilities.invokeLater(r);
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Thank you! Your answer is perfect to the question I asked. There is one more question because it has not fully solved my problem yet. Basically my program html parses String with same structures Range: Cost: Cooldown: . I save these individual structures into different String variables. Is it possible for me to put in a String Variable inside this html code? – DHH Dec 14 '13 at 17:44
  • That is an *entirely* different question for which you should start a [new quest1on](http://stackoverflow.com/questions/ask)! If this Q&A is relevant to the new question, link back to it. Don't presume that just because a person can answer one answer you ask, that they can answer *any* question you might ask. ;) – Andrew Thompson Dec 14 '13 at 17:48