Multi-line tooltips in Java?

前端 未结 10 1565
故里飘歌
故里飘歌 2020-12-02 12:31

I\'m trying to display tooltips in Java which may or may not be paragraph-length. How can I word-wrap long tooltips?

相关标签:
10条回答
  • 2020-12-02 13:27

    Example:

    jTextField1.setToolTipText("<html>"
                                  + "Line One"
                                  +"<br>"
                                  + "Line 2"
                             + "</html>");
    
    0 讨论(0)
  • 2020-12-02 13:29

    If you wrap the tooltip in <html> and </html> tags, you can break lines with <br> tags. See http://www.jguru.com/faq/view.jsp?EID=10653 for examples and discussion.

    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

    0 讨论(0)
  • 2020-12-02 13:30

    If you just add <html> to your tooltip text, it will appear to work until you have /*...*/ or HTML in your text. Use <html><pre> or escape your text. I also had to use <font size=3> to get it looking somewhat decent.

    0 讨论(0)
  • 2020-12-02 13:37

    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.

    0 讨论(0)
提交回复
热议问题