Given a JTextField
(or any JComponent
for that matter), how would one go about forcing that component\'s designated tooltip to appear, without any
You can access the ToolTipManager
, set the initial delay to 0 and send it an event. Don't forget to restore the values afterwards.
private void displayToolTip()
{
final ToolTipManager ttm = ToolTipManager.sharedInstance();
final MouseEvent event = new MouseEvent(this, 0, 0, 0,
0, 0, // X-Y of the mouse for the tool tip
0, false);
final int oldDelay = ttm.getInitialDelay();
final String oldText = textPane.getToolTipText(event);
textPane.setToolTipText("google!");
ttm.setInitialDelay(0);
ttm.setDismissDelay(1000);
ttm.mouseMoved(event);
new Timer().schedule(new TimerTask()
{
@Override
public void run()
{
ttm.setInitialDelay(oldDelay);
textPane.setToolTipText(oldText);
}
}, ttm.getDismissDelay());
}