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 http://rapid-img.de/images/b92e2112.jpg
On the screenshot you can see that I use:
-fx-border-radius: 10 10 10 10;
-fx-background-radius: 10 10 10 10;
Use the following css to get a drop shadow:
See the JavaFX CSS Reference guide for details.
To get the border in addition to the drop shadow, place your ImageView containing your Image in a StackPane. And apply the effect css above to the StackPane, in addition to a background and padding on the StackPane.
For example the css below applied to the StackPane containing your ImageView will provide a red border around your image:
If you want the background defining your border curved at the edges, then use:
That gets you an image like below where your image is enclosed in a shadowed border:
If you want to actually round the image itself, it's a bit trickier. You need to apply some code to:
Then you can get something like below:
Some code for that "BatmanLost.java":
With some FXML "batmanlostinthemix.fxml":
If you use the answer that jewelsea provided, then make sure to test first whether or not clipping is supported:
I try to avoid conditional features unless I have to use them. In my case, I wanted to make a picture round. So an alternative would be to use a
Circle
instead of anImageView
:The circle can be enhanced to use a shadow if supported: