JavaFX Tutorial Index

JavaFX Tutorial JavaFX Installation JavaFX Application Structure JavaFX Architecture

JavaFX Applications Charts

JavaFX Bar Chart JavaFX Bubble Chart JavaFX Pie Chart JavaFX Scatter Chart JavaFX Area Chart JavaFX Line Chart

JavaFX 2D Shapes

JavaFX Arc JavaFX Circle JavaFX Ellipse JavaFX Line JavaFX Polygon JavaFX Rectangle JavaFX Color JavaFX Gradient Color

JavaFX 3D Shapes

JavaFX Box JavaFX Cylinder JavaFX Sphere

JavaFX Animations

JavaFX Rotate Transition JavaFX Translate Transition JavaFX Fade Transition JavaFX Fill Transition JavaFX Parallel Transition JavaFX Path Transition JavaFX Pause Transition JavaFX Scale Transition JavaFX Sequential Transition JavaFX Stroke Transition

JavaFX CSS

JavaFX ID Selector JavaFX Inline Styles JavaFX Selectors

JavaFX Effect

JavaFX Blend JavaFX Bloom JavaFX Color Adjust JavaFX Color Input JavaFX Drop Shadow JavaFX Gaussian Blur JavaFX Glow JavaFX Image Input JavaFX Inner Shadow JavaFX Light Distant JavaFX Light Point JavaFX Light Spot JavaFX Lighting JavaFX Motion Blur JavaFX Reflection JavaFX Shadow

JavaFX Layouts

JavaFX Layouts JavaFX BorderPane JavaFX GridPane JavaFX StackPane JavaFX HBox JavaFX TilePane

JavaFX Event Handling

JavaFX Event Handling JavaFX Event Filters JavaFX Convenience Methods

JavaFX Transformation

JavaFX Transformation JavaFX Scaling JavaFX Rotation JavaFX Translation JavaFX Shear

JavaFX UI

JavaFX Menu JavaFX Button JavaFX Button Styling JavaFX CheckBox JavaFX File Chooser JavaFX HyperLink JavaFX Label JavaFX UI Controls JavaFX PasswordField JavaFX ProgressBar JavaFX RadioButton JavaFX ScrollBar JavaFX Slider JavaFX TextField

JavaFX Circle

In the JavaFX application, in order to draw a circle, the Circle class is used. The Circle allows us to join any points in the space. All methods needed for this purpose are present in the javafx.scene.shape.Circle class.

Properties and corresponding methods to create Circle:

1. centerX

This property of the Circle class allows us to define the center point of Circle which is X co-ordinate and the setCenterX() method helps to set it.

2. centerY

This property of the Circle class allows us to define the center point of Circle which is Y co-ordinate and the setCenterY() method helps to set it.

3. radius

This property of the Circle class allows us to define the width of the Circle and the setRadius() method helps to set it.

JavaFX 2D Shape – Circle using Setters

Example:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
  
public class CircleUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
        Group box = new Group();  
        Circle circle = new Circle();  
        circle.setCenterX(300);  
        circle.setCenterY(200);  
        circle.setRadius(150);  
        box.getChildren().addAll(circle);  
        Scene scene = new Scene(box,600,400);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle("JavaFX 2D shapes - Circle Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the Circle in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.Group, javafx.scene.shape.Circle.

Then we have created one class named CircleUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a Circle, a Group object is created which is then passed to the Scene class object.

The circle is created using the setters method to set centerX, centerY, and radius of the circle.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX 2D shapes - Circle Example”. Also, it displays a circle with defined centerX, centerY, and radius.

JavaFX 2D Shape Circle

JavaFX 2D Shape – Circle using Constructor

Example:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
  
public class CircleUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    Group box = new Group();  
        Circle circle = new Circle(200, 200, 120);
        box.getChildren().addAll(circle);  
        Scene scene = new Scene(box,600,400);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle("JavaFX 2D shapes - Circle using constructor Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the Circle using constructor in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.Group, javafx.scene.shape.Circle.

Then we have created one class named CircleUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold Circle created with a constructor, a Group object is created which is then passed to the Scene class object.

The circle is created using the constructor with the required values passed in it.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX 2D shapes – Circle using constructor Example”. Also, it displays circle as defined by constructor values.

JavaFX 2D Shape Circle

JavaFX 2D Shape – Circle with color filled in it

Example:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
  
public class CircleUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    Group box = new Group();  
        Circle circle = new Circle();  
        circle.setCenterX(300);  
        circle.setCenterY(200);  
        circle.setRadius(150);  
        circle.setFill(Color.BLUE);  
        box.getChildren().addAll(circle);  
         Scene scene = new Scene(box,600,400);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle("JavaFX 2D shapes - Circle Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the Circle with color filled in it in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.Group, javafx.scene.shape.Circle, javafx.scene.paint.Color.

Then we have created one class named CircleUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a color-filled Circle, a Group object is created which is then passed to the Scene class object.

The circle is created using the setters method to set centerX, centerY, and radius of the circle, and the setFill() method is used to set the color of the circle.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX 2D shapes - Circle Example". Also, it displays a circle with defined centerX, centerY, and radius with blue color filled in it.

JavaFX 2D Shape Circle