In this JavaFX source code example, we will see how to use the JavaFX DropShadow effect with an example.
DropShadow is a high-level effect that renders a shadow behind the content with the specified color, radius and offset.JavaFX DropShadow Example
The example creates a shadow around a rectangle.package sample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
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();
Rectangle rect = new Rectangle(0, 0, 100, 100);
rect.setFill(Color.RED);
DropShadow ds = new DropShadow(15, Color.DARKGREEN);
rect.setEffect(ds);
root.getChildren().add(rect);
Scene scene = new Scene(root, 250, 200, Color.WHITESMOKE);
stage.setTitle("DropShadow");
stage.setScene(scene);
stage.show();
}
}
Output:
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course