Reputation: 23
I'm trying to get a JLabel to display new line characters by using HTML tags. But the text I want is obtained from a method. Here's the line of code:
myLabel.setText("<html><pre>myCart.toString()</pre></html>");
But, this literally sets the text of the label to myCart.toString()
, not to the String that is returned by the method. Is there a way around this?
Upvotes: 2
Views: 1455
Reputation: 39
"
myCart.toString()"
should be
"
" + myCart.toString()+ ""
But I am only repeating what Eng.Fouad said
Upvotes: 0
Reputation: 535
myLabel.setText(MessageFormat.format("<html><pre>{0}</pre></html>",myCart.toString()));
Upvotes: 3
Reputation: 117645
Do you mean?
myLabel.setText("<html><pre>" + myCart.toString() + "</pre></html>");
or just:
myLabel.setText("<html><pre>" + myCart + "</pre></html>");
since toString()
will be called implicitly.
Upvotes: 7