JavaFX Polygons

Polygon can be defined as a plain figure with at least three straight sides forming a loop. In the case of polygons, we mainly considers the length of its sides and the interior angles. Triangles, squares, Pentagons, Hexagons,etc are all polygons.

In JavaFX, Polygon can be created by instantiating javafx.scene.shape.Polygon class. We need to pass a Double array into the class constructor representing X-Y coordinates of all the points of the polygon. The syntax is given below.

We can also create polygon by anonymously calling addAll() method on the reference returned by calling getPoints() method which is an instance method of Polygon class. However, we need to pass the double array into this method, which represents X-Y coordinates of the polygon. The syntax is given below.


The following example creates a polygon with three sides.

JavaFX Polygons Output
Next TopicJavaFX Cubic Curve

Hot Tutorials

Contact US

JavaFX Polygons