zcahfg2
zcahfg2

Reputation: 901

JLabel: using HTML and method call together

When using JLabel, is there a way to use HTML and method call together?

For example:

        JLabel speedLabel = new JLabel("<html><b>Speed: </b></html>" + plane.getSpeed());

This doesn't work.
It only shows Speed: and ignores the rest.

Upvotes: 1

Views: 50

Answers (2)

U X
U X

Reputation: 121

it is discarding the values after html close tag if you something like this it will work JLabel speedLabel = new JLabel("<html><b>Speed: " + plane.getSpeed() + "</b></html>");

Upvotes: 1

Alex
Alex

Reputation: 779

Try to change your code to this:

JLabel speedLabel = new JLabel("<html><b>Speed: " + plane.getSpeed() + " </b></html>");

The text, or in your case the airplane speed, that is probably a double, must be in between the <html> and </html> tags, to be recognized.

Upvotes: 2

Related Questions