JavaFX Reflection Example

In this JavaFX source code example, we will see how to use the JavaFX Reflection effect with an example. 

Reflection is an effect that renders a reflected version of the input below the actual input content.

JavaFX Reflection Example

The example applies a Reflection effect on a Text node.
package sample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.Reflection;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {

        initUI(stage);
    }

    private void initUI(Stage stage) {

        StackPane root = new StackPane();

        Text text = new Text();
        text.setText("Source Code Examples");
text.setFill(Color.STEELBLUE); text.setFont(Font.font("Serif", FontWeight.BOLD, 25)); Reflection ref = new Reflection(); text.setEffect(ref); root.getChildren().add(text); Scene scene = new Scene(root, 300, 250, Color.WHITESMOKE); stage.setTitle("Reflection"); stage.setScene(scene); stage.show(); } }

Output:


Comments