Display More then one Tooltips for a single component

Hi All, i want to display more then one tooltips intermittently(for a particular period of time) for a single component like(JButton,JTextField).i did search on forums but it's not there. thanks in advance Rajkumar.S
[245 byte] By [RajkumarSundararaja] at [2007-11-26 21:44:27]
# 1
define:"more than one tooltip".You can change the tooltip text by calling,component.setToolTipText("tooltip");Change this tooltip text as and when needed.
watfora at 2007-7-10 3:32:15 > top of Java-index,Desktop,Core GUI APIs...
# 2
When the cursor enter the particular component (JButton...)it displays the first tip for 2 seconds and then displays the next for the next 2 seconds and so on...
RajkumarSundararaja at 2007-7-10 3:32:15 > top of Java-index,Desktop,Core GUI APIs...
# 3
Cannot think of a clean solution. Try this,component.getTooltipText() is called everytime the tooltip is displayed for a component. Once this is called, change the tooltip for your component.
watfora at 2007-7-10 3:32:15 > top of Java-index,Desktop,Core GUI APIs...
# 4

You could extend JToolTip. Create a runnable and run it when the tooltip gets displayed... then from there change the tips (which you could have added to a list)..... all inside of an extended JToolTip class.

quite alot work for a small feature :)

but reusuable.. so mabe its worth the time ...

jEti182a at 2007-7-10 3:32:15 > top of Java-index,Desktop,Core GUI APIs...
# 5
give me any illustration...
RajkumarSundararaja at 2007-7-10 3:32:15 > top of Java-index,Desktop,Core GUI APIs...
# 6

Well you extend JToolTip and override a method that the GUI manager calls to display JToolTips.... im not sure maybe "setVisible" (deept down from Container..)...

from such a method call super(); to make sure we still have the original functionality and then add code to make a thread that changes the tips

by putting an instance of a class you create on the event dispatching thread via invokeLater...

a updating class would look basicly like this

class TipUpdater implements runnable{

//fields here

public TipUpdater(JToolTip refferenceToYourToolTip){

//set fields=parameter}

public void run(){

// loop here fetching strings from your tooltip list and change refferenceToYourToolTip.setToolTip(string);

}

};

Ok, i cant go much more into detail because i would have to go now and try it if/how it works... i hope this was a little help and gave you a basic idea to start from...

Swing Api JToolTip:

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JToolTip.html

Message was edited by:

jEti182

jEti182a at 2007-7-10 3:32:15 > top of Java-index,Desktop,Core GUI APIs...
# 7
The big question is why you would want to do this?I think this is a strange behavior for a tooltip.You can create a tooltip with multiple lines if you need using html: http://www.exampledepot.com/egs/javax.swing/tooltip_MultiLineTt.html
Rodney_McKaya at 2007-7-10 3:32:15 > top of Java-index,Desktop,Core GUI APIs...
# 8

Use a MouseListener. When mouseEntered event is generated you start a Timer that fires every 2 seconds. In the timer code you use component.setToolTipText(...) and this should refresh the tooltip. Then on mouseExited event you stop the timer.

You may also need to play with the ToolTipManager to keep the tooltip from hiding after the default time period.

camickra at 2007-7-10 3:32:15 > top of Java-index,Desktop,Core GUI APIs...