I'm trying to display tooltips in Java which may or may not be paragraph-length. How can I word-wrap long tooltips?
Multiline tooltips allow text to be displayed on more than one line. They are supported by version 4.70 and later of the common controls. Your application creates a multiline tooltip by sending a TTM_SETMAXTIPWIDTH message, specifying the width of the display rectangle.
Tooltips are small windows of text that popup when the user leaves the mouse cursor over a component for a second or two. They are used to explain the functionality of the component.
Use tabbedPane. addTab to add a tool tip.
1. Alternatively known as a balloon, help balloon, flyover help, or ScreenTip, a Tooltip is a text description near an object. The tooltip is displayed when the user hovers the mouse cursor over the object.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With