Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Make an ImageView with rounded corners and drop shadow.

cshMay 27 2013 — edited May 28 2013
Hi,

I have an Image and I want to display it with rounded borders and a drop shadow.

I tried to use a clip for the ImageView, but that also clips the shadow, leaving me with either the shadow OR the rounded corners.

Do you have any better idea? I basically want the shadow to have also rounded corners.

(The rectangle in my sample should be the ImageView actually)
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class TestApp2 extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }


    @Override
    public void start(Stage stage) throws Exception {
        VBox root = new VBox();
        root.setPadding(new Insets(20, 20, 20, 20));
        Rectangle rectangle = new Rectangle(0, 0, 200, 200);
        rectangle.setFill(Color.RED);

        root.getChildren().add(rectangle);

        Rectangle roundRect = new Rectangle(0, 0, 200, 200);
        roundRect.setArcHeight(50);
        roundRect.setArcWidth(50);

        rectangle.setClip(roundRect);
        rectangle.setEffect(new DropShadow());

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }
}
Edited by: csh on 27.05.2013 06:54
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 25 2013
Added on May 27 2013
2 comments
2,850 views