For my java application i need a Round rectangle with an outline that looks like a normal rectangle, like this

I know you can do that by drawing a normal rectangle and a RoundRect inside it but i don’t want to draw a RoundRect inside it because I want to draw something else in it.
So a round rect with normal corners. How do I draw that in Java?
The problem is that the rectangle looks like this if I use layers:
The corners are filled up with the wrong color. How do I prevent that?
I can think of two approaches. The first is to generate a
Shapethat represents the square outter edge and the rounded inner edge.The second would be to use a
AlphaCompositeto generate a masked result.Updated with Shape example
Finally had time to bang one out…
Updated
From a comment by Andrew, you could simplify the use of the shape example by using
AreaYou could replace the
paintComponentfrom the above example with this one…Which is much simpler 😀