Java Reference
In-Depth Information
See Also
To draw formatted text—as in a word processor—requires considerably more complexity.
You'll find an example in the online source under the JabberPoint program (see
ShowView.java ). This program also implements the Model-View-Controller pattern.
Drawing a Drop Shadow
Problem
You want to draw text or graphical objects with a “drop shadow” effect, as in Figure 12-3 .
Figure 12-3. Drop shadow text
Solution
Draw the component twice, with the darker shadow behind and the “real” color, slightly off-
set, in front.
Discussion
Program DropShadow in Example 12-2 does just this. It also uses a Font object from
java.awt to exercise some control over the typeface.
Example 12-2. DropShadow.java
public
public class
extends JComponent {
/** The text to draw */
protected
class DropShadow
DropShadow extends
protected String theLabel ;
/** The name of the font */
protected
protected String fontName ;
Search WWH ::




Custom Search