Constructors
There are three constructors in the JavaFX cylinder class:
-
Cylinder(): This is a simple constructor of the Cylinder class.
Setters are required to enter the height and radius values.
-
Cylinder(double radius_value, double height_value): It's a parameterized constructor of the JavaFX Cylinder class which allows us to pass the values of height and radius to its constructor.
- Cylinder( double radius_value, double height_value, int division_value): It's a parameterized constructor of the JavaFX Cylinder class in JavaFX which allows us to pass values of height, divisions, and radius to its constructor easily.
Steps To Draw 3D Cylinder
1. Create a Java class that inherits the Application class from the javafx.application package and implements the start() function.
2. In JavaFX, you can make a Cylinder by instantiating the Cylinder class, which is part of the javafx.scene.shape package.
3. Set the Cylinder's height and radius with their corresponding setters.
4. Create a group object in the start() method by instantiating the Group class from the javafx.scene package.
5. Create a Scene by instantiating the Scene class from the javafx.scene package.
6. The Stage class's setTitle() method can be used to change the title of the stage. This primaryStage is a Stage object that is supplied as a parameter to the scene class's start method.
7. The method setScene() of the Stage class can be used to add a Scene object to the stage.
8. The Stage class's show() method is used to display the contents of the scene.
9. Call the static method launch() of the Application class from the main method to start the JavaFX application.
Implementation Of JavaFX Cylinder Class
package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Cylinder;
import javafx.stage.Stage;
public class CylinderExample extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
/* TODO Auto-generated method stub for
creating the cylinder*/
Cylinder cyn = new Cylinder();
//Here the radius and height of cylinder is being set
cyn.setRadius(80);
cyn.setHeight(200);
cyn.setTranslateX(300);
cyn.setTranslateY(250);
//setting the camera
PerspectiveCamera camera = new PerspectiveCamera();
camera.setTranslateX(100);
camera.setTranslateY(100);
camera.setTranslateZ(0);
//setting the group and stage
Group root = new Group();
root.getChildren().addAll(cyn);
Scene scene = new Scene(root,450,300,Color.LIMEGREEN);
scene.setCamera(camera);
primaryStage.setScene(scene);
primaryStage.setTitle("Cylinder Example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

You can also try this code with Online Java Compiler
Run Code
How To Execute
To execute the above program. You can follow the given steps:
-
Open the terminal in the same folder where you have saved your source code.
-
Enter the below code and hit enter.
javac --module-path path/to/your/javaFx/modules --add-modules javafx.fxml,javafx.controls filename.java
-
After you hit enter a new file will automatically be generated namely filename.class
-
Now, enter the below command and hit enter to execute the above program.
java --module-path path/to/your/javaFx/modules --add-modules javafx.fxml,javafx.controls filename.java
- You have successfully executed the JavaFX program.
Output

Frequently Asked Questions
What are the use cases for the JavaFX library?
JavaFX is a Java library that can be used to create Rich Internet Applications. This library's applications can execute consistently across different platforms. JavaFX applications can run on a variety of platforms, including desktop computers, mobile phones, televisions, and tablets.
What is the recommended way of using JavaFX in your browser?
The Deployment Toolkit library is recommended for embedding a JavaFX application into a web page or launching it from within a web browser.
What are the alternatives of JavaFX?
The most popular JavaFX alternatives and competitors include GWT, Vaadin, Qt, JSF, and Electron.
Conclusion
In this blog, we discussed the JavaFX Cylinder class, its various use cases and properties. We also discussed the three JavaFX Cylinder class constructors. We also checked out its implementation and the produced results.
Cheers, you have reached the end. Hope you liked the blog, and it has added some knowledge to your life about JavaFX pause transition. Please look at these similar topics to learn more: JavaFX Introduction, JavaFX pause transition, JavaFX Box, JavaFX Sphere, JavaFX Lighting, JavaFX HBox, JavaFX VBox.
Refer to our Coding Ninjas Studio Guided Path to learn Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and even more! You can also check out the mock test series and participate in the contests hosted by Coding Ninjas Studio! But say you're just starting and want to learn about questions posed by tech titans like Amazon, Microsoft, Uber, and so on. In such a case, for placement preparations, you can also look at the problems, interview experiences, and interview bundle.
You should also consider our premium courses to offer your career advantage over others!
Please upvote our blogs if you find them useful and exciting!
Happy Coding!