Java Utililty Methods Swing Tooltip

List of utility methods to do Swing Tooltip

Description

The list of methods to do Swing Tooltip are organized into topic(s).

Method

voidaddClickTipEffect(final JComponent component)
add Click Tip Effect
component.setForeground(new java.awt.Color(51, 51, 255));
component.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
component.addMouseListener(new java.awt.event.MouseAdapter() {
    @Override
    public void mouseEntered(MouseEvent e) {
        component.setOpaque(true);
        component.setBackground(new java.awt.Color(51, 51, 255));
        component.setForeground(new java.awt.Color(255, 255, 255));
...
JComponentcreateMarker(int span, String tooltip)
create Marker
JLabel marker = new JLabel(MARKER_LABEL);
marker.setName(MARKER_NAME);
marker.setHorizontalAlignment(JLabel.CENTER);
marker.setOpaque(true);
marker.setBackground(Color.RED);
marker.setToolTipText(tooltip);
return marker;
JTextFieldcreateNumericInput(final String tooltip)
creates a JTextField.
NumberFormat integerFormat = NumberFormat.getIntegerInstance();
integerFormat.setGroupingUsed(false);
integerFormat.setParseIntegerOnly(true);
final JTextField urlInput = new JTextField();
urlInput.setToolTipText(tooltip);
urlInput.setDocument(new PlainDocument() {
    @Override
    public void insertString(final int offset, final String input, final AttributeSet a)
...
voiddisplayTooltip(JComponent component)
Forces the display of a component tooltop by sending it a CTRL-F1 key event.
component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_PRESSED, 0, KeyEvent.CTRL_MASK, KeyEvent.VK_F1,
        KeyEvent.CHAR_UNDEFINED));
voidhideToolTip(JComponent c)
hide Tool Tip
try {
    Method hideMethod = ToolTipManager.class.getDeclaredMethod("hide", JComponent.class);
    hideMethod.setAccessible(true);
    hideMethod.invoke(ToolTipManager.sharedInstance(), c);
} catch (Exception e) {
    throw new RuntimeException(e);
intperformMultipleReplacements(final Document theDocument, final String theRegexToSearch, final String theReplacement)
Performs as many replacements as possible of pattern regex in document, starting at document index theStart.
return performMultipleReplacements(theDocument, theRegexToSearch, theReplacement, 0);
voidsetLongerTooltips()
(re-)shows tooltips earlier (10 milliseconds) and longer (20 seconds)
ToolTipManager sharedInstance = ToolTipManager.sharedInstance();
sharedInstance.setReshowDelay(10);
sharedInstance.setInitialDelay(10);
sharedInstance.setDismissDelay(60 * 1000);
voidsetTooltipDismissDelay()
set Tooltip Dismiss Delay
ToolTipManager.sharedInstance().setDismissDelay(TOOLTIP_DISMISS_DELAY);
voidshowTooltipNow(JComponent c)
show Tooltip Now
Action toolTipAction = c.getActionMap().get("postTip");
if (toolTipAction != null) {
    ActionEvent postTip = new ActionEvent(c, ActionEvent.ACTION_PERFORMED, "");
    toolTipAction.actionPerformed(postTip);
voidshowToolTipNow(JComponent component)
show Tool Tip Now
ToolTipManager manager = ToolTipManager.sharedInstance();
int oldDelay = manager.getInitialDelay();
manager.setInitialDelay(0);
manager.mouseMoved(
        new MouseEvent(component, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 0, 0, 0, false));
manager.setInitialDelay(oldDelay);