A BToolTip is a small floating window that appears in front of another Widget. It contains a single
line of text, and generally provides information about the function of the Widget it is displayed
over.
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.
getComponent
public JToolTip getComponent()
Get the java.awt.Component corresponding to this Widget.
- getComponent in interface Widget
getShowingToolTip
public static BToolTip getShowingToolTip()
Get the currently showing tool tip, or null if none is showing.
getText
public String getText()
Get the text to display on the tool tip.
hide
public static void hide()
Hide the currently showing tool tip.
processEvent
public void processEvent(ToolTipEvent event)
Display the tool tip in response to a ToolTipEvent.
event
- the event from which to determine where to display the tool tip
setText
public void setText(String text)
Set the text to display on the tool tip.
show
public void show(Widget widget,
Point where)
Display the tool tip.
widget
- the Widget over which to display the tool tipwhere
- the location at which to display the tool tip