JavaFX - 2D Shapes Rounded Rectangle

In JavaFX, you can draw a rectangle either with sharp edges or with arched edges as shown in the following diagram.

Rounded Rectangle

The one with arched edges is known as a rounded rectangle and it has two additional properties namely −

  • arcHeight − The vertical diameter of the arc, at the corners of a rounded rectangle.

  • arcWidth − The horizontal diameter of the arc at the corners of a rounded rectangle.

Arc Width Height

By default, JavaFX creates a rectangle with sharp edges unless you set the height and width of the arc to +ve values (0<) using their respective setter methods setArcHeight() and setArcWidth().


Following is a program which generates a rounded rectangle using JavaFX. Save this code in a file with the name

import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 
import javafx.scene.shape.Rectangle; 
public class RoundedRectangle extends Application { 
   public void start(Stage stage) {         
      //Drawing a Rectangle 
      Rectangle rectangle = new Rectangle();  
      //Setting the properties of the rectangle 
      //Setting the height and width of the arc 
      //Creating a Group object  
      Group root = new Group(rectangle); 
      //Creating a scene object 
      Scene scene = new Scene(root, 600, 300);  
      //Setting title to the Stage 
      stage.setTitle("Drawing a Rectangle");
      //Adding scene to the stage 
      //Displaying the contents of the stage; 
   public static void main(String args[]){ 

Compile and execute the saved java file from the command prompt using the following commands.

java RoundedRectangle

On executing, the above program generates a JavaFX window displaying a rounded rectangle as shown below.

Drawing Rounded Rectangle