Given a JTextField
(or any JComponent
for that matter), how would one go about forcing that component's designated tooltip to appear, without any direct input event from the user? In other words, why is there no JComponent.setTooltipVisible(boolean)
?
The only way (besides creating your own Tooltip window) I've found is to emmulate the CTRL+F1 keystroke on focus:
new FocusAdapter()
{
@Override
public void focusGained(FocusEvent e)
{
try
{
KeyEvent ke = new KeyEvent(e.getComponent(), KeyEvent.KEY_PRESSED,
System.currentTimeMillis(), InputEvent.CTRL_MASK,
KeyEvent.VK_F1, KeyEvent.CHAR_UNDEFINED);
e.getComponent().dispatchEvent(ke);
}
catch (Throwable e1)
{e1.printStackTrace();}
}
}
Unfortunately, the tooltip will disappear as soon as you move your mouse (outside of the component) or after a delay (see ToolTipManager.setDismissDelay
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With