APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public final Class ToolTipManager

extends MouseAdapter
implements MouseMotionListener
Class Inheritance
All Implemented Interfaces
java.awt.event.MouseMotionListener, java.util.EventListener
Imports
java.awt.event.*, java.awt.*, java.util.Objects, javax.swing.event.MenuKeyEvent, .MenuKeyListener

Manages all the ToolTips in the system.

ToolTipManager contains numerous properties for configuring how long it will take for the tooltips to become visible, and how long till they hide. Consider a component that has a different tooltip based on where the mouse is, such as JTree. When the mouse moves into the JTree and over a region that has a valid tooltip, the tooltip will become visible after initialDelay milliseconds. After dismissDelay milliseconds the tooltip will be hidden. If the mouse is over a region that has a valid tooltip, and the tooltip is currently visible, when the mouse moves to a region that doesn't have a valid tooltip the tooltip will be hidden. If the mouse then moves back into a region that has a valid tooltip within reshowDelay milliseconds, the tooltip will immediately be shown, otherwise the tooltip will be shown again after initialDelay milliseconds.

Authors
Dave Moore, Rich Schiavi
Since
1.2
See Also
JComponent#createToolTip

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
protected class
private class
protected class
ToolTipManager.outsideTimerAction

Outside timer action.

protected class
ToolTipManager.stillInsideTimerAction

Still inside timer action.

Field Summary

Modifier and TypeField and Description
private KeyListener
pack-priv boolean
pack-priv Timer
pack-priv Timer
private FocusListener
protected boolean
heavyWeightPopupEnabled

Heavyweight popup enabled.

private KeyStroke
pack-priv JComponent
pack-priv Timer
protected boolean
lightWeightPopupEnabled

Lightweight popup enabled.

private static ToolTipManager
pack-priv MouseEvent
private MouseMotionListener
private Rectangle
private Rectangle
private KeyStroke
pack-priv Point
pack-priv boolean
pack-priv JToolTip
private boolean
pack-priv transient Popup
pack-priv String
private Window
window

The Window tip is being displayed in. This will be non-null if the Window tip is in differs from that of insideComponent's Window.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
checkForTipChange(MouseEvent event)

Checks to see if the tooltip needs to be changed in response to the MouseMoved event event.

private FocusListener
pack-priv static Frame
public int

Returns:

an integer representing the dismissal delay value, in milliseconds
getDismissDelay
()

Returns the dismissal delay value.

private GraphicsConfiguration
private int
public int

Returns:

an integer representing the initial delay value, in milliseconds
getInitialDelay
()

Returns the initial delay value.

private int
getPopupFitHeight(Rectangle popupRectInScreen, Component invoker)

private int
getPopupFitWidth(Rectangle popupRectInScreen, Component invoker)

public int

Returns:

reshow delay property
getReshowDelay
()

Returns the reshow delay property.

private int
private void
hide(JComponent source)

pack-priv void
private void
public boolean

Returns:

true if this object is enabled, false otherwise
isEnabled
()

Returns true if this object is enabled.

public boolean

Returns:

true if lightweight ToolTips are in use
isLightWeightPopupEnabled
()

Returns true if lightweight (all-Java) Tooltips are in use, or false if heavyweight (native peer) Tooltips are being used.

public void
mouseDragged(MouseEvent
the event in question
event
)

Overrides java.awt.event.MouseAdapter.mouseDragged.

Implements java.awt.event.MouseMotionListener.mouseDragged.

Called when the mouse is pressed and dragged.

public void
mouseEntered(MouseEvent
the event in question
event
)

Overrides java.awt.event.MouseAdapter.mouseEntered.

Implements java.awt.event.MouseListener.mouseEntered.

Called when the mouse enters the region of a component.

public void
mouseExited(MouseEvent
the event in question
event
)

Overrides java.awt.event.MouseAdapter.mouseExited.

Implements java.awt.event.MouseListener.mouseExited.

Called when the mouse exits the region of a component.

public void
mouseMoved(MouseEvent
the event in question
event
)

Overrides java.awt.event.MouseAdapter.mouseMoved.

Implements java.awt.event.MouseMotionListener.mouseMoved.

Called when the mouse is moved.

public void
mousePressed(MouseEvent
the event in question
event
)

Overrides java.awt.event.MouseAdapter.mousePressed.

Implements java.awt.event.MouseListener.mousePressed.

Called when the mouse is pressed.

public void
registerComponent(JComponent
a JComponent object to add
component
)

Registers a component for tooltip management.

public void
setDismissDelay(int
the number of milliseconds to delay before taking away the tooltip
milliseconds
)

Specifies the dismissal delay value.

public void
setEnabled(boolean
true to enable the tip, false otherwise
flag
)

Enables or disables the tooltip.

public void
setInitialDelay(int
the number of milliseconds to delay (after the cursor has paused) before displaying the tooltip
milliseconds
)

Specifies the initial delay value.

public void
setLightWeightPopupEnabled(boolean
true if a lightweight panel is desired, false otherwise
aFlag
)

When displaying the JToolTip, the ToolTipManager chooses to use a lightweight JPanel if it fits.

public void
setReshowDelay(int
time in milliseconds
milliseconds
)

Used to specify the amount of time before the user has to wait initialDelay milliseconds before a tooltip will be shown.

public static ToolTipManager

Returns:

a shared ToolTipManager object
sharedInstance
()

Returns a shared ToolTipManager instance.

private void
show(JComponent source)

pack-priv void
public void
unregisterComponent(JComponent
a JComponent object to remove
component
)

Removes a component from tooltip control.

Inherited from java.awt.event.MouseAdapter:
mouseClickedmouseReleasedmouseWheelMoved

Field Detail

accessibilityKeyListenerback to summary
private KeyListener accessibilityKeyListener
enabledback to summary
pack-priv boolean enabled
enterTimerback to summary
pack-priv Timer enterTimer
exitTimerback to summary
pack-priv Timer exitTimer
focusChangeListenerback to summary
private FocusListener focusChangeListener
heavyWeightPopupEnabledback to summary
protected boolean heavyWeightPopupEnabled

Heavyweight popup enabled.

hideTipback to summary
private KeyStroke hideTip
insideComponentback to summary
pack-priv JComponent insideComponent
insideTimerback to summary
pack-priv Timer insideTimer
lightWeightPopupEnabledback to summary
protected boolean lightWeightPopupEnabled

Lightweight popup enabled.

managerback to summary
private static ToolTipManager manager
mouseEventback to summary
pack-priv MouseEvent mouseEvent
moveBeforeEnterListenerback to summary
private MouseMotionListener moveBeforeEnterListener
popupFrameRectback to summary
private Rectangle popupFrameRect
popupRectback to summary
private Rectangle popupRect
postTipback to summary
private KeyStroke postTip
preferredLocationback to summary
pack-priv Point preferredLocation
showImmediatelyback to summary
pack-priv boolean showImmediately
tipback to summary
pack-priv JToolTip tip
tipShowingback to summary
private boolean tipShowing
tipWindowback to summary
pack-priv transient Popup tipWindow
toolTipTextback to summary
pack-priv String toolTipText
windowback to summary
private Window window

The Window tip is being displayed in. This will be non-null if the Window tip is in differs from that of insideComponent's Window.

Constructor Detail

ToolTipManagerback to summary
pack-priv ToolTipManager()
Annotations
@SuppressWarnings:deprecation

Method Detail

checkForTipChangeback to summary
private void checkForTipChange(MouseEvent event)

Checks to see if the tooltip needs to be changed in response to the MouseMoved event event.

createFocusChangeListenerback to summary
private FocusListener createFocusChangeListener()
frameForComponentback to summary
pack-priv static Frame frameForComponent(Component component)
getDismissDelayback to summary
public int getDismissDelay()

Returns the dismissal delay value.

Returns:int

an integer representing the dismissal delay value, in milliseconds

See Also
setDismissDelay
getDrawingGCback to summary
private GraphicsConfiguration getDrawingGC(Point toFind)
getHeightAdjustback to summary
private int getHeightAdjust(Rectangle a, Rectangle b)
getInitialDelayback to summary
public int getInitialDelay()

Returns the initial delay value.

Returns:int

an integer representing the initial delay value, in milliseconds

See Also
setInitialDelay
getPopupFitHeightback to summary
private int getPopupFitHeight(Rectangle popupRectInScreen, Component invoker)
getPopupFitWidthback to summary
private int getPopupFitWidth(Rectangle popupRectInScreen, Component invoker)
getReshowDelayback to summary
public int getReshowDelay()

Returns the reshow delay property.

Returns:int

reshow delay property

See Also
setReshowDelay
getWidthAdjustback to summary
private int getWidthAdjust(Rectangle a, Rectangle b)
hideback to summary
private void hide(JComponent source)
hideTipWindowback to summary
pack-priv void hideTipWindow()
initiateToolTipback to summary
private void initiateToolTip(MouseEvent event)
isEnabledback to summary
public boolean isEnabled()

Returns true if this object is enabled.

Returns:boolean

true if this object is enabled, false otherwise

isLightWeightPopupEnabledback to summary
public boolean isLightWeightPopupEnabled()

Returns true if lightweight (all-Java) Tooltips are in use, or false if heavyweight (native peer) Tooltips are being used.

Returns:boolean

true if lightweight ToolTips are in use

mouseDraggedback to summary
public void mouseDragged(MouseEvent event)

Overrides java.awt.event.MouseAdapter.mouseDragged.

Implements java.awt.event.MouseMotionListener.mouseDragged.

Called when the mouse is pressed and dragged. Does nothing.

Parameters
event:MouseEvent

the event in question

mouseEnteredback to summary
public void mouseEntered(MouseEvent event)

Overrides java.awt.event.MouseAdapter.mouseEntered.

Implements java.awt.event.MouseListener.mouseEntered.

Called when the mouse enters the region of a component. This determines whether the tool tip should be shown.

Parameters
event:MouseEvent

the event in question

mouseExitedback to summary
public void mouseExited(MouseEvent event)

Overrides java.awt.event.MouseAdapter.mouseExited.

Implements java.awt.event.MouseListener.mouseExited.

Called when the mouse exits the region of a component. Any tool tip showing should be hidden.

Parameters
event:MouseEvent

the event in question

mouseMovedback to summary
public void mouseMoved(MouseEvent event)

Overrides java.awt.event.MouseAdapter.mouseMoved.

Implements java.awt.event.MouseMotionListener.mouseMoved.

Called when the mouse is moved. Determines whether the tool tip should be displayed.

Parameters
event:MouseEvent

the event in question

mousePressedback to summary
public void mousePressed(MouseEvent event)

Overrides java.awt.event.MouseAdapter.mousePressed.

Implements java.awt.event.MouseListener.mousePressed.

Called when the mouse is pressed. Any tool tip showing should be hidden.

Parameters
event:MouseEvent

the event in question

registerComponentback to summary
public void registerComponent(JComponent component)

Registers a component for tooltip management.

This will register key bindings to show and hide the tooltip text only if component has focus bindings. This is done so that components that are not normally focus traversable, such as JLabel, are not made focus traversable as a result of invoking this method.

Parameters
component:JComponent

a JComponent object to add

See Also
JComponent#isFocusTraversable
setDismissDelayback to summary
public void setDismissDelay(int milliseconds)

Specifies the dismissal delay value.

Parameters
milliseconds:int

the number of milliseconds to delay before taking away the tooltip

See Also
getDismissDelay
setEnabledback to summary
public void setEnabled(boolean flag)

Enables or disables the tooltip.

Parameters
flag:boolean

true to enable the tip, false otherwise

setInitialDelayback to summary
public void setInitialDelay(int milliseconds)

Specifies the initial delay value.

Parameters
milliseconds:int

the number of milliseconds to delay (after the cursor has paused) before displaying the tooltip

See Also
getInitialDelay
setLightWeightPopupEnabledback to summary
public void setLightWeightPopupEnabled(boolean aFlag)

When displaying the JToolTip, the ToolTipManager chooses to use a lightweight JPanel if it fits. This method allows you to disable this feature. You have to do disable it if your application mixes light weight and heavy weights components.

Parameters
aFlag:boolean

true if a lightweight panel is desired, false otherwise

setReshowDelayback to summary
public void setReshowDelay(int milliseconds)

Used to specify the amount of time before the user has to wait initialDelay milliseconds before a tooltip will be shown. That is, if the tooltip is hidden, and the user moves into a region of the same Component that has a valid tooltip within milliseconds milliseconds the tooltip will immediately be shown. Otherwise, if the user moves into a region with a valid tooltip after milliseconds milliseconds, the user will have to wait an additional initialDelay milliseconds before the tooltip is shown again.

Parameters
milliseconds:int

time in milliseconds

See Also
getReshowDelay
sharedInstanceback to summary
public static ToolTipManager sharedInstance()

Returns a shared ToolTipManager instance.

Returns:ToolTipManager

a shared ToolTipManager object

showback to summary
private void show(JComponent source)
showTipWindowback to summary
pack-priv void showTipWindow()
unregisterComponentback to summary
public void unregisterComponent(JComponent component)

Removes a component from tooltip control.

Parameters
component:JComponent

a JComponent object to remove

javax.swing back to summary

private Class ToolTipManager.AccessibilityKeyListener

extends KeyAdapter
implements MenuKeyListener
Class Inheritance
All Implemented Interfaces
javax.swing.event.MenuKeyListener, java.util.EventListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
keyPressed(KeyEvent e)

Overrides java.awt.event.KeyAdapter.keyPressed.

Implements java.awt.event.KeyListener.keyPressed.

Invoked when a key has been pressed.

public void
menuKeyPressed(MenuKeyEvent e)

Implements javax.swing.event.MenuKeyListener.menuKeyPressed.

Invoked when a key has been pressed.

public void
menuKeyReleased(MenuKeyEvent e)

Implements javax.swing.event.MenuKeyListener.menuKeyReleased.

Invoked when a key has been released.

public void
menuKeyTyped(MenuKeyEvent e)

Implements javax.swing.event.MenuKeyListener.menuKeyTyped.

Invoked when a key has been typed.

Inherited from java.awt.event.KeyAdapter:
keyReleasedkeyTyped

Constructor Detail

AccessibilityKeyListenerback to summary
private AccessibilityKeyListener()

Method Detail

keyPressedback to summary
public void keyPressed(KeyEvent e)

Overrides java.awt.event.KeyAdapter.keyPressed.

Implements java.awt.event.KeyListener.keyPressed.

Doc from java.awt.event.KeyAdapter.keyPressed.

Invoked when a key has been pressed.

menuKeyPressedback to summary
public void menuKeyPressed(MenuKeyEvent e)

Implements javax.swing.event.MenuKeyListener.menuKeyPressed.

Doc from javax.swing.event.MenuKeyListener.menuKeyPressed.

Invoked when a key has been pressed.

Annotations
@Override
menuKeyReleasedback to summary
public void menuKeyReleased(MenuKeyEvent e)

Implements javax.swing.event.MenuKeyListener.menuKeyReleased.

Doc from javax.swing.event.MenuKeyListener.menuKeyReleased.

Invoked when a key has been released.

Annotations
@Override
menuKeyTypedback to summary
public void menuKeyTyped(MenuKeyEvent e)

Implements javax.swing.event.MenuKeyListener.menuKeyTyped.

Doc from javax.swing.event.MenuKeyListener.menuKeyTyped.

Invoked when a key has been typed. This event occurs when a key press is followed by a key release.

Annotations
@Override
javax.swing back to summary

protected Class ToolTipManager.insideTimerAction

extends Object
implements ActionListener
Class Inheritance
All Implemented Interfaces
java.awt.event.ActionListener, java.util.EventListener

Inside timer action.

Constructor Summary

AccessConstructor and Description
protected
insideTimerAction()

Constructs an insideTimerAction.

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

insideTimerActionback to summary
protected insideTimerAction()

Constructs an insideTimerAction.

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

javax.swing back to summary

private Class ToolTipManager.MoveBeforeEnterListener

extends MouseMotionAdapter
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
mouseMoved(MouseEvent e)

Overrides java.awt.event.MouseMotionAdapter.mouseMoved.

Implements java.awt.event.MouseMotionListener.mouseMoved.

Invoked when the mouse button has been moved on a component (with no buttons no down).

Inherited from java.awt.event.MouseMotionAdapter:
mouseDragged

Constructor Detail

MoveBeforeEnterListenerback to summary
private MoveBeforeEnterListener()

Method Detail

mouseMovedback to summary
public void mouseMoved(MouseEvent e)

Overrides java.awt.event.MouseMotionAdapter.mouseMoved.

Implements java.awt.event.MouseMotionListener.mouseMoved.

Doc from java.awt.event.MouseMotionAdapter.mouseMoved.

Invoked when the mouse button has been moved on a component (with no buttons no down).

javax.swing back to summary

protected Class ToolTipManager.outsideTimerAction

extends Object
implements ActionListener
Class Inheritance
All Implemented Interfaces
java.awt.event.ActionListener, java.util.EventListener

Outside timer action.

Constructor Summary

AccessConstructor and Description
protected
outsideTimerAction()

Constructs an outsideTimerAction.

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

outsideTimerActionback to summary
protected outsideTimerAction()

Constructs an outsideTimerAction.

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

javax.swing back to summary

protected Class ToolTipManager.stillInsideTimerAction

extends Object
implements ActionListener
Class Inheritance
All Implemented Interfaces
java.awt.event.ActionListener, java.util.EventListener

Still inside timer action.

Constructor Summary

AccessConstructor and Description
protected
stillInsideTimerAction()

Constructs a stillInsideTimerAction.

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

stillInsideTimerActionback to summary
protected stillInsideTimerAction()

Constructs a stillInsideTimerAction.

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.