Is posible have multiple lines in ToolTip?

R

RC

I tried

String toolTipText = "Line1\nLine2\rLine3<br />";

myJComponent.setToolTipText(toolTipText);

But I only got the single line.

Is possible to have multiple lines in ToolTip?
If yes, how do I set the multiple line mode?

Thank Q very much in advance!
 
M

Mark Holland

RC said:
I tried

String toolTipText = "Line1\nLine2\rLine3<br />";

myJComponent.setToolTipText(toolTipText);

But I only got the single line.

Is possible to have multiple lines in ToolTip?
If yes, how do I set the multiple line mode?

Thank Q very much in advance!

It is possible to do this, since (I think) tool tips are displayed in
a kind of customised JLabel.
You were fairly close with your first guess - the answer is to format
your tool-tip text with html.

e.g.
String toolTipText = "<html>Line1<br>Line2<br>Line3</html>";
myJComponent.setToolTipText(toolTipText);

Of course, if you do this then you need to escape any special html
characters in your text.
For example, if you want to display the text "a < b\n line2" then you
need:

String toolTipText = "<html>a &lt; b<br> line2</html";

Because of this, some people have written their own classes which you
can find using google.
One I found is this http://www.codeguru.com/java/articles/122.shtml,
although I didn't test it.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top