
324
|
Chapter 8, Rendering
#64 Turn the Spotlight on Swing
HACK
You can even go one step further: the more light you shed, the less darkness
there is. For instance, when several books are found, it is likely that the
search query was not very precise. This means the user will be more inter-
ested in lots of items. When the query yields only a few results, it is likely
that the user wants to see only a few specific items.
As you create several spotlights—one per result—the interface is less dark-
ened than with only one spotlight. If you take a close look at Figure 8-13,
you’ll be able to perceive the other books. Nevertheless, a single search
result will prevent the user from seeing the other books, as shown in
Figure 8-14.
Add the Spotlight
The implementation of spotlights for Swing is divided into two classes,
SpotlightPanel and Spotlight. The first class is a glass pane that needs to be
set up on a frame, and the second defines the location and the shape of a
spotlight. Here is an example of how to use spotlights:
SpotlightPanel glassPane = new SpotlightPanel( );
setGlassPane(glassPane);
Spotlight s1 = glassPane.addSpotlight(0, 0, 25, 50);
Spotlight s2 = glassPane.addSpotlight(100, 100, 30);
Figure 8-14. With only one spotlight, it is almost impossible to see the other books