Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

javafx

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 grid.setGridLinesVisible(true); and that works fine, but I am sure this isn't supposed to be used for that.

I tried setting a border with nodes[j][i].setStroke(Color.BLACK); 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!

like image 559
Johannes Mols Avatar asked Dec 09 '25 02:12

Johannes Mols


1 Answers

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

nodes[j][i].setStrokeType(StrokeType.Inside);
like image 60
pzaenger Avatar answered Dec 11 '25 15:12

pzaenger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!