Drawing Basic Shapes in JavaFX

By Vaibhav Choudhary, October 29, 2008

With the JavaFX technology it is easy to use primitive shapes.

Understanding the Code

The code shown in Figure 1 creates some of the primitive shapes supported by the JavaFX programming language.

Source Code
scene: Scene {
        fill:Color.BLACK
        content: [
               Rectangle {
                ...
               },
               Circle {
                ...
               },
               ...
               ...

Figure 1: A Small Part of Main.fx

Customizing the Code

To further customize the application, change a few of the attributes such as changing palette colors.

Source Code
    var patch_color1 = Color.GOLD;
    var patch_color2 = Color.GREEN;
    var patch_color3 = Color.DARKRED;
    var patch_color4 = Color.DARKBLUE;
    var patch_color5 = Color.GRAY;

Figure 2: Changing Colors

Figure 3 shows the change in Color and Gradient


Figure 3: Different Gradients for Shapes