I have a question. I am creating an application where an Arc length changes and I want that arc inside a borderpane, but when i change the length of the Arc it will get centered, so it doesn't look like a circle that's getting filled. Actually what i need is an arc and calculate it's position (the center of the borderpane) by it's maximum length (360). Can someone help me with this problem? Thank you very much.
JavaFX center an resizable arc in a borderpane
2.5k views Asked by Gilian Joosen At
2
There are 2 answers
4
On
Inside BorderPane (or StackPane) the alignment is done according to the bounding box of the shape (top left, center, bottom etc.). Therefore the center point of the arc will move and will not give you the effect you want.
Instead, put the arc inside an AnchorPane (if you want to use BorderPane, put AnchorPane inside a region (left, right, center etc.) of the BorderPane). This will fix the center point of the arc even if you change the arc length and give you the effect of a circle getting filled with the increasing arc length.
Create a Group. Place a rectangle in the group which is the size of a full circle (e.g. the rectangle's height and width is set to the circle's diameter), then add the arc to the group, with the arc layout position set to the circle's radius. Place the Group in a StackPane so that the fixed size Group will be centered within a resizable Region. Place the StackPane in the center of your BorderPane. Set the minimum size of the StackPane to zero so that it can be sized smaller than the Group, keeping the Group centered and clipped within it's visible bounds. Add some controls to the bottom of the BorderPane so that you can control the length of the arc dynamically.