JavaFX 2D Shapes Types of Arc - JavaFX

What is JavaFX 2D Shapes Types of Arc?

In JavaFX, you can draw three kinds of arc’s namely −

  • Open − An arc which is not closed at all is known as an open arc.
  • Chord − A chord is a type of an arc which is closed by straight line.
  • Round − The Round arc is an arc which is closed by joining the starting and end point to the center of the ellipse.

JavaFX - 2D Shapes Types of Arc

You may set the type of the arc the usage of the technique setType() by passing any of the following properties − ArcType.OPEN, ArcType.CHORD, ArcType.round.

Steps to Draw Arc

To draw an arc in JavaFX, follow the steps given below.

Step 1: creating a class

Create a Java class and inherit the application class of the package javafx.application and implement the start() method of this class as follows.

Step 2: Creating an Arc

You may create an arc in JavaFX by means of instantiating the class named Arc which belongs to a package javafx.scene.shape. you can instantiate this class as proven below.

Step 3: Setting Properties to the Arc

Specify the x, y coordinates of the center of the Ellipse (of which this arc is part of). those coordinates consist of – radiusX, radiusY, start angle and length of the arc using their respective setter methods as proven in the following code block.

You may also set the type of the arc (round, chord open) through the usage of the setType() method.

Step 4: Setting the Type of the Arc

You can set the type of the arc using the method setType() as shown in the following code block.

Step 5: Creating a Group Object

In the start() technique create a group object by using instantiating the class named group, which belongs to the package javafx.scene.

Pass the Arc (node) item created inside the previous step as a parameter to the constructor of the group class. This have to be done if you want to upload it to the group as shown below –

Step 6: Creating a Scene Object

Create a Scene through instantiating the class named Scene which belongs to the package javafx.scene. To this class pass the institution object (root) created within the preceding step.

Similarly to the root item, you may also pass double parameters representing height and width of the screen together with the object of the group class as follows.

Step 7: Setting the Title of the Stage

You may set the name to the level using the setTitle() technique of the stage class. The primaryStage is a level object that is passed to the start method of the scene class as a parameter.

Using the primaryStage object, set the title of the scene as sample application as follows.

Step 8: Adding Scene to the Stage

You may add a Scene object to the stage the use of the method setScene() of the class named stage. upload the Scene object prepared inside the previous steps the usage of this method as follows.

Step 9: Displaying the Contents of the Stage

Display the contents of the scene using the method named show() of the Stage class as follows.

Step 10: Launching the Application

Launch the JavaFX application through calling the static method launch()of the application class from the primary method as follows.


Following is a program which generates an arc. Save this code in a file with the name

Collect and execute the saved Java file from the command prompt using the following commands.

On executing, the above program generates a JavaFX window displaying an arc as shown in the following screenshot.

JavaFX - 2D Shapes Types of Arc

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

JavaFX Topics