Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on making the tool tip to multiple lines.  RSS feed

 
ganggang lu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTree, and each tree node associates with a tooltip. I do not know how to break the tooltip(which is a string) to mutiple lines since my tooltip is pretty long......
Thanks a lot,
ganggang
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have to use a customized look and feel to accomplish a multiline tooltip.
Or take a look at what Zafir Anjum came up with:
http://www.codeguru.com/java/articles/122.shtml
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or take a look at DTooltip, part of dog.gui.
I found lots of solutions with a quick google search.
 
M.K.A. Monster
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that HTML was allowed in the tooltip see the Swing demo provided in the SDK. You can use "<br>" to simply add a new line I think.
Regards,
Mark Monster
 
ganggang lu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, the tooltip breaks to multiple lines when I use HTML <br> tag, but the tooltip font is much bigger than the regular tooltip without HTML tags. Do you know why?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought an html tag would work, but when I add <br> to my tooltip text, it just displays <br> with the rest of the text (all on one line). I'm probably doing something obviously wrong, but what is it?
 
ganggang lu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you also need to include the <html> and </html> tags. I tried, it works perfect. Also you can use other html snippets to define the tooltip font size, color etc...
Thank you all.
 
ganggang lu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dick, here is the code, use <p> instead.
import javax.swing.JFrame ;
import javax.swing.JButton ;
import java.awt.FlowLayout ;
public class FooFrame extends JFrame
{
private void constructGUI()
{
JButton button = new JButton( "Button" ) ;
button.setToolTipText("<html>This is<p>Tooltip text.</html>");
getContentPane().setLayout( new FlowLayout() ) ;
getContentPane().add( button ) ;
}

public static void main( String[] args )
{
FooFrame f = new FooFrame() ;
f.setSize( 200 , 200 ) ;
f.constructGUI() ;
f.setVisible( true ) ;
}
}
 
ganggang lu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, your name is Dirk, not Dick
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ganggang lu:
Sorry, your name is Dirk, not Dick

Yeah - we keep TELLING him that he really needs to change it - but he just keeps ignoring us
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, the missing <html> tag. Why didn't I think of that? I was probably too busy confused by my own identity.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!