Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting tooltips  RSS feed

 
Cathy Song
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a JTable which is created using a table model. I am setting tooltips for the columns using the following code: (from java almanac)



Since the text in the column is very long, I would like to format the tooltip to be displayed in multiple lines. Can anyone suggest how to approach this problem?

Thanks.

Regards,
Cathy.
 
Eric Snell
Greenhorn
Posts: 28
Java Mac MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDK 1.5 is supposed to support multi-line tooltips, but I haven't used it yet. For earlier JDKs you needed your own tooltip. Here's one that supports multiple lines:


You'll need to add the following code to your JTable subclass:



Now your table will return a tooltip that will display multiple lines delimited by '/n'. You just need to format your text so that it has multiple lines, which should be relatively straightforward.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, that's some code. I did it this way. I created method in a Utility class:



And to use it I just did something like:



the setToolTipText was a method that the DefaultTreeCellRenderer uses to set the tooltip of a Leaf Node. You can give that string to whatever tooltip you need it on.
[ June 11, 2004: Message edited by: Gregg Bolinger ]
 
Cathy Song
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!