Skip to main content

Async ToolTip

4 replies [Last post]
phenderson
Offline
Joined: 2005-02-16
Points: 0

Friday afternoon thoughts.

Wouldn't it be nice if JComponent actually fired property change events for tool tips.

For example, I have a control where getting the tool tip text is slow and involves network IO.

So I over ride getToolTip() to kick off a swing worker, then when the worker completes it performs a setToolTip(). Setting the tool tip causes a property change event, which is detected by the popup window which changes it's content from "loading'" to the real text.

I bet this has already been done, and I'm just living in a cave? So enlighten me.

Peter

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexfromsun
Offline
Joined: 2005-09-05
Points: 0

Hello Peter

Calling setToolTip() from getToolTip() is not the best technique,

I actually don't see how it can work reliably

I would override JComponent.createToolTip() and subclass JToolTip

to make it call swing worker, update the text when it is ready etc...

Thanks

alexp

kleopatra
Offline
Joined: 2003-06-11
Points: 0

Peter,

sounds like you are mis-using the tooltip mechanism ;-) It's meant for showing additional infos related to something under the current mouse location in a time-frame defined by the ToolTipManager, usually reasonbly near to "immediate". If getting the infos is longish the mouse location tends to have changed considerably in that time. Then what do you expect:

- users must not move the mouse during the time interval?
- tooltip appears at a location unrelated to the mouse location?

Both not very attractive ... My suggestion would be to not use the tooltip directly (or at least not expect the tooltipManager to handle the delayed) but think about an alternative (as you do with your custom popup).

My 0.02 (Euro :-) cents
Jeanette

phenderson
Offline
Joined: 2005-02-16
Points: 0

Thanks for the excellent replies.

Indeed I am perhaps abusing tool tips. But allow me to explain in a little more detail.

In my application, I have a list of "tasks" in a JTable. The list contains basic stuff task id, start, end, subject. A task can be linked to multiple business objects (contact, company, sales order, work orders, controlled documents, accounts, purchase orders, blah blah) and assigned to multiple users.

So I'd like my tool tip to contain some details about the task along with who and what it is linked with. This lead me to think "I know AJAX style tool tip" which pokes the database to get the full details.

No joy with property change events on tool tips has lead me down an interesting path with some clever SQL.

I am now building html tool tip text in a function within the DB server. This text is an additional column on the list of tasks returned to the application. Not perhaps the best solution as it adds extra load to the DB server (but Postgresql is so awesome it can handle the load easy) and consumes extra bandwidth.
Compared to an AJAX type solution, which would only retrieve the tool tip popup info when it was actually needed, and therefore only add load to the DB when required and consume less network bandwidth. (Because for a single "task" I can get the tool tip info in ~200ms or so, even over ADSL)

Ah well.
Back to the code face.

Peter.

walterln
Offline
Joined: 2007-04-17
Points: 0

I don't know if it has been done, you could file a RFE :).

As a workaround, you could try to send a fake mouse moved event to the ToolTipManager (if the tool tip loads between initial + dismiss delay), which checks for text change.