Search code examples
javastringjbuttonjcomponent

In java, how do I add line breaks to a JButton's tooltip?


I have a JButton that uses setToolTipText(String str) and I have a few lines of writing in the tooltip that need to to be separated by line breaks. I tried concatenating + "/n" at the end of each line of text right before I wanted the line break to go, but it did not do anything. JToolTip text doesn't have a constructor with a JTextArea and I couldn't see anything in JTextArea that allowed it to convert to a String. Anyone have any ideas? Also, how do I get a JToolTip to last longer than the default 3 seconds? Thank you for your time.


Solution

  • Use HTML.

    Set the tooltip to "<html>My multi-line<br>tooltip.</html>"