Java Reference
In-Depth Information
}
Directory "Sketcher 9 with tooltips"
The
String
value for the
SHORT_DESCRIPTION
key represents the tooltip text for an object you create
from an action. You should keep the tooltip text short because it is displayed on the fly. Add the following
statements to the end of the
createElementTypeActions()
method:
lineAction.putValue(SHORT_DESCRIPTION, "Draw lines");
rectangleAction.putValue(SHORT_DESCRIPTION, "Draw rectangles");
circleAction.putValue(SHORT_DESCRIPTION, "Draw circles");
curveAction.putValue(SHORT_DESCRIPTION, "Draw curves");
Directory "Sketcher 9 with tooltips"
The statements you add to
createElementColorActions()
method to implement tooltips are much the
same:
redAction.putValue(SHORT_DESCRIPTION, "Draw in red");
blueAction.putValue(SHORT_DESCRIPTION, "Draw in blue");
greenAction.putValue(SHORT_DESCRIPTION, "Draw in green");
yellowAction.putValue(SHORT_DESCRIPTION, "Draw in yellow");
Directory "Sketcher 9 with tooltips"
You can try the tooltips out. Just recompile the
SketcherFrame
class and run Sketcher again. You should
be able to see the tooltip when you let the cursor linger over a button, as
Figure 18-12
illustrates.