Boolena
Boolena

Reputation: 225

why is html in java not working?

when i use this code it does not work; the text does not become bold. Why?

    label1 = new JLabel();
    label1.setText("Welcome, <html><strong>Hussein</strong></html>.");

Upvotes: 0

Views: 1217

Answers (4)

Raju Sharma
Raju Sharma

Reputation: 2516

You forgot to add body tag ,Try This :

label1 = new JLabel();
    label1.setText("<html><body>Welcome ,<strong> Hussein</strong></body></html>");

Upvotes: 0

ZaoTaoBao
ZaoTaoBao

Reputation: 2615

try this:

JLabel label = new JLabel("<html><yourTagHere><yourOtherTagHere>this is your text</yourOtherTagHere></yourTagHere></html>");

Upvotes: 0

Stunner
Stunner

Reputation: 1121

Why are you mixing html and java. tag is in html. This is how you do in java

label = new JLabel("A label");
label.setFont(new Font("Serif", Font.BOLD, 14));

Upvotes: -1

Mena
Mena

Reputation: 48404

Your HTML syntax is bad, since your String does not start with the html DOM root.

Try something in the lines of:

label1.setText("<html>Welcome <strong>Hussein</strong>.</html>");

Find a tutorial here.

Upvotes: 4

Related Questions