JavaFX Reflection effect

Description

JavaFX Reflection effect

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Reflection;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class Main extends Application {

    public static void main(String[] args) {
        Application.launch(args);/* w w  w  .  ja  v a 2s.c  o m*/
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Changing Text Fonts");
        Group root = new Group();
        Scene scene = new Scene(root, 330, 250, Color.WHITE);

        // Serif with drop shadow
        Text test2 = new Text(50, 50, "Java 7 Recipes");
        Font serif = Font.font("Serif", 30);
        test2.setFont(serif);
        test2.setFill(Color.RED);
        DropShadow dropShadow = new DropShadow();
        dropShadow.setOffsetX(2.0f);
        dropShadow.setOffsetY(2.0f);
        dropShadow.setColor(Color.rgb(50, 50, 50, .588));
        test2.setEffect(dropShadow);
        root.getChildren().add(test2);


        // SanSerif
        Text test3 = new Text(50, 100, "Java 7 Recipes");
        Font sanSerif = Font.font("SanSerif", 30);
        test3.setFont(sanSerif);
        test3.setFill(Color.BLUE);
        root.getChildren().add(test3);

        // Dialog
        Text test4 = new Text(50, 150, "Java 7 Recipes");
        Font dialogFont = Font.font("Dialog", 30);
        test4.setFont(dialogFont);
        test4.setFill(Color.rgb(0, 255, 0));
        root.getChildren().add(test4);

        // Monospaced
        Text test5 = new Text(50, 200, "Java 7 Recipes");
        Font monoFont = Font.font("Monospaced", 30);
        test5.setFont(monoFont);
        test5.setFill(Color.BLACK);
        root.getChildren().add(test5);

        Reflection refl = new Reflection();
        refl.setFraction(0.8f);
        test5.setEffect(refl);

        primaryStage.setScene(scene);
        primaryStage.show();
    }
}



PreviousNext

Related