Adding reflections

Another simple but powerful effect is Reflection

The API is straightforward:

// chapter8/basiceffects/ReflectionDemo.javapublic void start(Stage primaryStage) {    Reflection reflection = new Reflection();    reflection.setTopOffset(5);  // how far from source the reflection should start    reflection.setFraction(0.7); // size of the reflection    // starting and ending opacity levels    reflection.setTopOpacity(0.05);       reflection.setBottomOpacity(0.5);    Button button = new Button("Button");    button.setEffect(reflection);    primaryStage.setTitle("Reflection Demo");    primaryStage.setScene(new Scene(new StackPane(button), 300, 250));    primaryStage.show();}

The preceding code produces the following:

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.