The Lighting-effect simulates a light source shining across the object, creating a slight
shadow and reflection area on the surface of the object. This essentially generates an
elevated 3D-like effect around the object (perfect for creating buttons). The Lighting
effect exposes a number of properties including the light:Light property. The Light
class provides further control over the direction and elevation of the light source being
used to generate the effect.
In this recipe, the Lighting effect causes the circle to be re-rendered with a slight elevation
and a surface shadow that falls around the edge of the new shape. The circle received an
instance of DistantLight , through the light property, which represents a distant light
source. The DistantLight instance provides control over the angle of the light source
through the azimuth property (you can also control elevation). The surfaceScale property
specifies the height of the surface elevation used to simulate the lighting effect.
The DropShadow-effect re-renders the node with a shadow behind it. It automatically
figures out the shape of the shadow and provides a default blur size. This gives the object
the appearance of floating on the screen. The DropShadow effect offers several properties
to control how the shadow is generated including the blur level of the shadow's edge, the
shadow's color, the shadow's x/y offset, and the radius of the blur. For our example, we simply
specify the x and y distance offset of the shadow, as shown in the previous screenshot.
The algorithm which creates effects can be CPU intensive. If you have a scene
graph containing hundreds of nodes with complicated effects, you will pay a
penalty through performance degradation. Therefore, you should understand
the implications of using a specific effect before applying it on a large scale.
Though our recipe only covers two effects, JavaFX provides an extensive set of built-in effect
classes located at javafx.scene.effect . The next table shows a list of all available
effects as of version 1.2.
Blends two effects to create a third effect from the
Makes bright portion of an input glow
Available blur effects
Allows adjustment of hue, saturation, brightness, and
A low-level effect that shifts each pixel by a specified value
Fills a rectangular region with a given paint