Multi-line tooltips in Java?
If you wrap the tooltip in <html>
and </html>
tags, you can break lines with <br>
tags. See https://web.archive.org/web/20060625031340/http://www.jguru.com/faq/view.jsp?EID=10653 for examples and discussion. Main take-awy from that discussion: fButton.setToolTipText("<html><font face=\"sansserif\" color=\"green\">first line<br>second line</font></html>");
Or you can use the JMultiLineToolTip class that can be found many places on the net, including https://github.com/ls-cwi/yoshiko-app/blob/master/src/main/java/com/yoshiko/internal/view/JMultiLineToolTip.java
Tooltip text which starts with "<html>
" will be treated as HTML. Of course that might be very wide HTML.
You can override JComponent.createTooltip to replace the tooltip with your own component which can display whatevee you like.
I know this one is quite old but i found a quite simple solution using HTML code!
Just use a HTML Paragraph with a fixed width:
setToolTipText("<html><p width=\"500\">" +value+"</p></html>");
Example:
jTextField1.setToolTipText("<html>"
+ "Line One"
+"<br>"
+ "Line 2"
+ "</html>");