Add Drop Shadow to Text with DropShadow class : DropShadow « JavaFX « Java






Add Drop Shadow to Text with DropShadow class

 

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
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);
    }
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Text Fonts");
        Group root = new Group();
        Scene scene = new Scene(root, 550, 250, Color.WHITE);

        Text text = new Text(150, 50, "JavaFX from Java2s.com");
        text.setFill(Color.BLUE);
        DropShadow dropShadow = new DropShadow();
        dropShadow.setOffsetX(2.0f);
        dropShadow.setOffsetY(4.0f);
        dropShadow.setColor(Color.rgb(150, 50, 50, .688));
        text.setEffect(dropShadow);
        
        root.getChildren().add(text);

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

   
  








Related examples in the same category

1.Adding Drop Shadow to a Shape