Add drop shadow to Shape in JavaFX - Java JavaFX

Java examples for JavaFX:Effect

Description

Add drop shadow to Shape in JavaFX

Demo Code

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.shape.Ellipse;
import javafx.stage.Stage;

public class Main extends Application {

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

  @Override
  public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 306, 550, Color.WHITE);

    Ellipse bigCircle = new Ellipse(100, 100, 50, 75 / 2);
    bigCircle.setTranslateY(123);
    bigCircle.setStrokeWidth(3);
    bigCircle.setStroke(Color.BLACK);
    bigCircle.setFill(Color.WHITE);

    DropShadow dropShadow = new DropShadow();
    dropShadow.setOffsetX(2.0f);
    dropShadow.setOffsetY(2.0f);
    dropShadow.setColor(Color.rgb(50, 50, 50, .588));

    bigCircle.setEffect(dropShadow);

    root.getChildren().add(bigCircle);

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

Related Tutorials