public class BToolTip extends Widget
The user triggers a tool tip by placing the mouse pointer over a Widget and leaving it there for a
fixed amount of time. When this happens, the Widget sends out a ToolTipEvent
.
The program should respond to the event by calling either show()
or
processEvent()
to display the tool tip.
The easiest way of doing this is to have the BToolTip listen for the event directly. For example, you can set a fixed String as the tool tip for a button by invoking:
button.addEventLink(ToolTipEvent.class, new BToolTip("Do Not Press This Button"));
In some cases, you may want to do additional processing before the tool tip is displayed. For example, you might want to customize the tool tip text based on the mouse location, or exercise finer control over where the tool tip appears. In these cases, your program should listen for the event and handle it in the appropriate way.
As an example, the following code will display a tool tip over a BTable, showing the row and column the mouse is currently pointing to:
table.addEventLink(ToolTipEvent.class, new Object() { void processEvent(ToolTipEvent ev) { Point pos = ev.getPoint(); String text = "("+table.findRow(pos)+", "+table.findColumn(pos)+")"; new BToolTip(text).processEvent(ev); } });
There can only be one tool tip showing at any time. It will automatically be hidden as soon as
a new tool tip is shown, or the mouse is moved away from the Widget. You can call
getShowingToolTip()
to get the currently displayed
tool tip, or hide()
to hide it.
Constructor and Description |
---|
BToolTip()
Create a new BToolTip with no text.
|
BToolTip(java.lang.String text)
Create a new BToolTip.
|
Modifier and Type | Method and Description |
---|---|
javax.swing.JToolTip |
getComponent()
Get the java.awt.Component corresponding to this Widget.
|
static BToolTip |
getShowingToolTip()
Get the currently showing tool tip, or null if none is showing.
|
java.lang.String |
getText()
Get the text to display on the tool tip.
|
static void |
hide()
Hide the currently showing tool tip.
|
void |
processEvent(ToolTipEvent event)
Display the tool tip in response to a ToolTipEvent.
|
void |
setText(java.lang.String text)
Set the text to display on the tool tip.
|
void |
show(Widget widget,
java.awt.Point where)
Display the tool tip.
|
addEventLink, dispatchEvent, getBackground, getBounds, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible
addEventLink, addEventLink, removeEventLink
public BToolTip()
public BToolTip(java.lang.String text)
text
- the text to display in the tool tippublic javax.swing.JToolTip getComponent()
Widget
getComponent
in class Widget
public java.lang.String getText()
public void setText(java.lang.String text)
public void show(Widget widget, java.awt.Point where)
widget
- the Widget over which to display the tool tipwhere
- the location at which to display the tool tippublic void processEvent(ToolTipEvent event)
event
- the event from which to determine where to display the tool tippublic static BToolTip getShowingToolTip()
public static void hide()
Written by Peter Eastman.