Johannes Mols Johannes Mols - 11 months ago 63
Java Question

JavaFX: Setting a border within a rectangle to keep the width and height

So, I have a grid of rectangles in my scene and I want to give it a border to visually seperate it to the others. I am currently using

and that works fine, but I am sure this isn't supposed to be used for that.

I tried setting a border with
and this works too, but now my whole grid is getting a lot bigger because it's drawing the border on the outside of the rectangle and therefore resizing it.

Is there a way to draw a border/stroke inside of a rectangle to keep the transformation?
I already looked up the documentation but there isn't such a function.

Thanks for the help!

Answer Source

You can use setStrokeType for your rectangles to draw the border inside using StrokeType.Inside: