updating tooltip text without moving the mouse

hello,

how do i update/refresh the tooltip with new text, without waiting for the mouse to be moved (and without using Robot to move the mouse). i've attached sample code at the bottom which exhibits some unexpected behavior.

if you move your mouse over the second button and hit any key, then the tooltip text is changed, but does not get updated on the screen until the mouse is moved. this is causing problems with a 3rd party charting bean that uses tooltips to display some labels.

any thoughts? thanks,

raj

import javax.swing.JFrame;

import java.awt.FlowLayout;

import javax.swing.JButton;

import java.awt.event.*;

import java.awt.*;

import java.awt.AWTException;

/*****************************

//Runthis program and hover mouse over the Test 2 button.

//Initially, you will see "Testing 2" tooltip. Now hit any

//key on key pad, the tooltip of Test 2 button should now be

//"updated". Notice that there is no change to tool tip

//until you move the mouse.

*****************************/

publicclass TestSwingJToolTipextends JFrame

{

JButton test1, test2;

public TestSwingJToolTip(){

getContentPane().setLayout(new FlowLayout());

test1 =new JButton("Test 1");

test2 =new JButton("Test 2");

test2.setToolTipText("Testing 2");

// if any key is typed, update the data

addKeyListener(new KeyAdapter(){

publicvoid keyTyped(KeyEvent e){

test2.setToolTipText("Updated");

}

});

getContentPane().add(test1);

getContentPane().add(test2);

}

publicstaticvoid main(String[] args)

{

TestSwingJToolTip tc =new TestSwingJToolTip();

tc.setSize(500, 300);

tc.setVisible(true);

}

}

[3227 byte] By [rajito] at [2007-9-26 2:39:17]
# 1
anyone?
rajito at 2007-6-29 10:11:36 > top of Java-index,Archived Forums,Swing...
# 2

you have to build up a new class that extends the ToolTipManager class, there you implement a new Method e.g. showMyToolTip() or whatever you need to do... then you copy the code from the mouse-method (e.g. mouseEntered() ) to your method..when you need to call it..just call it.. ;-)

greetz

chris

Ruvenkiller at 2007-6-29 10:11:36 > top of Java-index,Archived Forums,Swing...