
Create Menus with Drop Shadows #11
Chapter 1, Basic JComponents
|
49
HACK
One nice thing about assembling the drop-down from standard compo-
nents is that it will still look good when used with a different Look and Feel.
Everything the user sees on the screen is some subclass of the standard
JButton, but it is just presented in a non-traditional manner. If you switch to
another theme where standard buttons are shaped differently, the custom
component adapts automatically.
H A C K
#11
Create Menus with Drop Shadows Hack #11
This hack explores a simple way to create drop shadows on menus
throughout an entire application with minimal code changes.
Many modern operating systems provide menus with interesting effects to
make them jump off the screen. One of the most common is the drop
shadow. Some programs even provide shadows themselves when the host
operating system does not. For years, a lack of low-level graphics support
has denied Swing programs access to these kinds of cool effects. But not any
more! Most of the effects can be duplicated with Swing’s robust theming
ability.
Most custom effects require either subclassing a component or messing with
graphics overlays. I tried a variety of techniques to create this hack, but I
kept coming across the same problem over and over. If I wanted to draw a
shadow, I had to change the sizing of each menu item, plus its background,
plus the pop-up frame itself. That ...