Border-Radius and Shadow on ImageView

Viewed 79705

I want to apply a border-radius and a shadow in JavaFX.

In CSS3 it would be:

box-shadow: rgba(0,0,0,0.8) 0 0 10px;
border-radius: 3px;

Now I want this in JavaFX, but even the border-radius is not working in the JavaFX Scene Builder. Here is a screenshot of my problem:

JavaFX Screenshot
(source: rapid-img.de)

On the screenshot you can see that I use:

-fx-border-radius: 10 10 10 10;
-fx-background-radius: 10 10 10 10;
3 Answers

Thanks martin for pointing ImagePattern

enter image description here

Rectangle rectangle = new Rectangle(0, 0, 280, 180);
rectangle.setArcWidth(30.0);   // Corner radius
rectangle.setArcHeight(30.0);

ImagePattern pattern = new ImagePattern(
    new Image("file:images/mustang-gt.jpg", 280, 180, false, false) // Resizing
);

rectangle.setFill(pattern);
rectangle.setEffect(new DropShadow(20, Color.BLACK));  // Shadow

Note that here Iam resizing the image to match the size of the rectangle during its load to ensure smoothness.

Related