• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Help on making the tool tip to multiple lines.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, your name is Dirk, not Dick
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What's that smell? Hey, sniff this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic