Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2004

Tip: Looking for answers? Try searching our database.

Custom tooltip renderer in JTable

Thread view: 
Chas Douglass - 08 Nov 2004 20:58 GMT
I am trying to get a multi-line tooltip on cells in a JTable.  Basically
the cell is a large chunk of text, and I'd like to display it in the
tooltip.

First, you have to get any tooltip to display in a JTable.  I created a
custom renderer which sets the tooltip text correctly, but the text
displays all in a single line.  This works in the JTable.

I found some code for a multi-line tooltip renderer, but it relies on the
JComponent.createToolTip() method.  I override this method in my custom
renderer, but it is never called when the renderer is used by a JTable.

Am I on the right track?  If so, how do I get the JTable to use my
multiline tooltip renderer?

Thanks.

Chas Douglass
Andrew Thompson - 08 Nov 2004 21:15 GMT
> I am trying to get a multi-line tooltip on cells in a JTable.  

Did you try lurking in the group for a couple of days
before asking, or googling the group?
<http://groups.google.com/groups?selm=13klxlfeqhzg2$.msad2puffqve.dlg@40tude.net>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Chas Douglass - 08 Nov 2004 23:01 GMT
>> I am trying to get a multi-line tooltip on cells in a JTable.  
>
> Did you try lurking in the group for a couple of days
> before asking, or googling the group?
[snip]

Yes, I did.  And while I'm sure you're frustrated with the number of
people that don't do that, I find your response frustrating since it
assumes that I didn't.   What was that line from "Annie Hall"?  Something
about "thanks for reducing me to a stereotype"??

I fully understand that tooltips will render HTML.  I'm sorry I didn't
mention that in my original post, but it's difficult to know how many
things I should list that aren't what I want.

And while I'm certainly no expert on HTML, it would appear that it
requires me to calculate my own line breaks and insert the "<br>" tokens,
yes?

Clearly I should have mentioned (and I apologize for omitting it) that I
would like the text to "auto-wrap" in a "reasonably sized" tooltip.

Something like the automatic javadoc popups in Eclipse, but with word
wrap.

The path I was following was to subclass JToolTip and have it use a
JTextArea for the display of the text.  While this seems reasonable to
me, JTable seems to have other ideas on how tooltips should be rendered.

Ideally, clicking on the cell to edit it would just change the tooltip
into an editable text area, as well.

Chas Douglass
Rene Ruppert - 08 Nov 2004 21:29 GMT
Hi,

>I am trying to get a multi-line tooltip on cells in a JTable.  Basically
> the cell is a large chunk of text, and I'd like to display it in the
> tooltip.

Swing tooltips are capable of interpreting (simple) HTML - try inserting
<br> or similiar tags.

cu

René
Babu Kalakrishnan - 09 Nov 2004 07:11 GMT
> I am trying to get a multi-line tooltip on cells in a JTable.  Basically
> the cell is a large chunk of text, and I'd like to display it in the
[quoted text clipped - 10 lines]
> Am I on the right track?  If so, how do I get the JTable to use my
> multiline tooltip renderer?

The TooltipManager would call the createTooltip method on the JTable in
order to create the tooltip, not on the renderer - so you need to
override the JTable's method instead of that of the renderer.

The JTable just "borrows" the text from the renderer if the renderer has
defined one. Since the renderer is not physically present on the screen,
they cannot receive events and hence there's no point registering them
with the TooltipManager.

BK
Chas Douglass - 09 Nov 2004 15:20 GMT
[snip]

>> Am I on the right track?  If so, how do I get the JTable to use my
>> multiline tooltip renderer?
>
> The TooltipManager would call the createTooltip method on the JTable
> in order to create the tooltip, not on the renderer - so you need to
> override the JTable's method instead of that of the renderer.

[snip]

Thanks, overriding createToolTip on the JTable fixed it.  Exactly the
pointer I needed.

Chas Douglass
guilian Zhao - 30 Nov 2004 21:57 GMT
How did you the overriding createToolTip method? Can you please send me the code?

Thanks,
Jennifer


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.