JavaFX: How to Create Reflections
A reflection in JavaFX projects an inverted copy of the shape in front of and below the shape, creating the impression that the shape is sitting on a reflective surface. You can create a reflection by using the Reflection class, whose members are shown in this table.
|Reflection()||Creates a new Reflection effect with default settings.|
|void setBottomOpacity(double value)||The opacity (0.0 to 1.0) at the bottom edge of the reflection.
The default is 0.
|void setFraction(double value)||The portion of the shape that will be reflected. The default is
|void setTopOffset(double value)||The distance between the bottom of the shape and the start of
the reflection. The default is 0.
|void setTopOpacity(double value)||The opacity (0.0 to 1.0) at the top of the reflection. The
default is 0.5.
This figure shows a Text shape with a reflection applied. The following code was used to create this shape:
Text t = new Text("Reflection"); t.setFont(new Font("Times New Roman", 96)); t.setFill(Color.LIGHTGRAY); t.setStroke(Color.BLACK); t.setEffect(new Reflection());