Table of contents
1.
Introduction
2.
Constructors
3.
Arc Creation Properties and Associated Methods:
4.
Types of Arc
5.
Program to create an Arc
6.
Program to create an arc and set its fill
7.
Program to create an arc and define its fill and arc type
8.
Frequently Asked Questions
8.1.
What is JavaFX?
8.2.
Which method is used to define the radius of the arc?
8.3.
What is JavaFX group?
9.
Conclusion
Last Updated: Aug 13, 2025
Medium

JavaFX Arc

Author Nagendra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

An arc is a portion of a circle or ellipse's circumference. Wherever necessary, it must be produced in some JavaFX applications. JavaFX enables us to instantiate JavaFX.scene.shape.Arc to construct the Arc on the GUI. The Arc class is a component of JavaFX. The Arc class constructs an arc based on the specified values for the arc's centre, start angle, length, and radius. This blog describes the JavaFX arc in detail, including its constructors, arc creation techniques, and different programs.

Without further ado, let's start by learning the constructors of the Arc Class.

Constructors

The class's constructors are:

  • Arc(): It is used to create a new instance of the arc class.
     
  • Arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length): It is used to create an arc using the provided coordinates and the values.
     

Let's discuss the JavaFX arc creation methods and their properties.

Arc Creation Properties and Associated Methods:

The different methods used for creating a JavaFX arc are as follows:

Arc Creation Methods and Description

Let's now have a look at different types of arcs in JavaFX.

Types of Arc

You can create three different types of arcs in JavaFX, including

  • Open: An arc that is completely unclosed is referred to as being open.
     
  • Chord: A chord is a particular kind of arc that is enclosed by a straight line.
     
  • Round: Round arcs are arcs that are closed by connecting the ellipse's centre to its beginning and end points.
     

By giving any of the following properties—ArcType.OPENArcType.CHORD, or ArcType.Round—to the method setType(), you can change the type of the arc.

Let's examine how to create an arc using a program.

Program to create an Arc

The following code snippet describes creating an arc.

Code:

//Importing packages
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.shape.Arc;
import javafx.scene.shape.DrawMode;
import javafx.scene.layout.*;
import javafx.scene.Group;
import javafx.event.ActionEvent;
import javafx.scene.control.*;
import javafx.stage.Stage;
public class Draw_Arc extends Application {
     public void start(Stage stage)
    {      
        stage.setTitle("Drawing Arc"); //Title
        Arc draw_arc = new Arc(100.0f, 100.0f, 100.0f, 100.0f, 0.0f, 100.0f);//Creating arc
        Group group = new Group(arc); //Creating Group
        //translating the X,Y positions
        draw_arc.setTranslateX(100);
        draw_arc.setTranslateY(100);
 
        //Creating Scene
        Scene scene = new Scene(group, 500, 300);
        stage.setScene(scene);
 
        stage.show();
    }
 
    //main method
    public static void main(String args[])
    {
        launch(args);
    }
}
You can also try this code with Online Java Compiler
Run Code

Output:

Output

Explanation

This program constructs an Arc using the center, radius, start angle, and arc length passed as arguments. The arc will be developed within a scene that is hosted within a stage. The stage's title is provided through the setTitle() method. The arc is then attached after creating a Group. The group is associated with the location. The show() method is used to display the outcome.

Program to create an arc and set its fill

The following code snippet describes how to create a JavaFX arc and define its fill.

Code:

//importing packages
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.scene.shape.DrawMode;
import javafx.scene.Group;
import javafx.scene.shape.Arc;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.scene.shape.ArcType;
import javafx.scene.paint.Color;
public class Draw_arc_fill extends Application {
 
   
    public void start(Stage stage)
    {
        stage.setTitle("Draw Arc"); //Title
 
        Arc arc = new Arc(); //Creating Arc
 
        // Center od Arc
        arc.setCenterX(100.0f);
        arc.setCenterY(100.0f);
 
        //Radius of arc
 
        arc.setRadiusX(100.0f);
        arc.setRadiusY(100.0f);
 
        // set start angle and length
        arc.setStartAngle(0.0f);
        arc.setLength(270.0f);
 
        Group group = new Group(arc); //Creating Group
 
        // translate the arc to a position
        arc.setTranslateX(100);
        arc.setTranslateY(100);
 
        //Color of the Arc
        arc.setFill(Color.RED);
 
        // create a scene
        Scene scene = new Scene(group, 400, 200);
        stage.setScene(scene);
        stage.show();
    }
 
    //main method
    public static void main(String args[])
    {
        launch(args);
    }
}
You can also try this code with Online Java Compiler
Run Code

Output:

Output

Explanation:

This programme produces the JavaFX arc with the help of the setCenterX()setCenterY(), setRadiusX()setRadiusY(), and setLength() functions. The arc will be developed within a scene that is hosted within a stage. The stage's title is provided through the setTitle() method. The arc is then attached after creating a Group. The group is associated with the location. The show() method is used to display the outcome. The fill for the arc is set using the method setFill().

Program to create an arc and define its fill and arc type

The following code snippet describes how to create a JavaFX arc and define its fill and arc type.

Code:

//importing Packages
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.shape.DrawMode;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.scene.shape.Arc;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.shape.ArcType;
import javafx.scene.paint.Color;
public class Draw_arc extends Application {
 
    public void start(Stage stage)
    {
        stage.setTitle("Drawing Arc"); //title
 
        Arc arc = new Arc(); //creating Arc
 
        //center
        arc.setCenterX(100.0f);
        arc.setCenterY(100.0f);
 
        // set radius
        arc.setRadiusX(100.0f);
        arc.setRadiusY(100.0f);
 
        arc.setStartAngle(0.0f);//Start angle
        arc.setLength(270.0f);//length
 
        Group group = new Group(arc);//Creating group
 
        arc.setTranslateX(100);
        arc.setTranslateY(100);
 
        arc.setFill(Color.GREEN);//Arc Color
 
        arc.setType(ArcType.ROUND);//Type of Arc
 
        Scene scene = new Scene(group, 400, 200); //Creating scene
 
        stage.setScene(scene);
 
        stage.show();
    }
 
    public static void main(String args[])
    {
        launch(args);
    }
}
You can also try this code with Online Java Compiler
Run Code

Output:

Output

Explanation:

This program produces the JavaFX arc with the help of the setCenterX()setCenterY(), setRadiusX()setRadiusY(), and setLength() functions. The arc will be developed within a scene that is hosted within a stage. The stage's title is provided through the setTitle() method. The arc is then attached after creating a Group. The group is associated with the location. The show() method is used to display the outcome. The functions setFill() and setArcType() are used to set the arc's fill and type, respectively.

Frequently Asked Questions

What is JavaFX?

JavaFX is a collection of graphics and media packages that give programmers the ability to design, build, debug, test, and deploy rich client applications that work reliably across several platforms.

Which method is used to define the radius of the arc?

The radiusX() and radiusY() are used to define the X-coordinate and Y-coordinate of the center of the arc.

What is JavaFX group?

The JavaFX group class is a component of JavaFX. A Group's node count is contained within it. A Group is not immediately resizable and will take on the aggregate boundaries of its offspring.

Conclusion

In this article, we have extensively discussed the details of the JavaFX arc along with its constructors, methods used for arc creation, and different programs for drawing arcs.

We hope that this blog has helped you enhance your knowledge regarding JavaFX Arc, and if you would like to learn more, check out our articles on JavaFX. You can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews. Do upvote our blog to help other ninjas grow. Happy Coding!!

Thank You!!
Live masterclass