JavaFX Rectangle

In general, Rectangles can be defined as the geometrical figure consists of four sides, out of which, the opposite sides are always equal and the angle between the two adjacent sides is 90 degree. A Rectangle with four equal sides is called square.

JavaFX library allows the developers to create a rectangle by instantiating javafx.scene.shape.Rectangle class.

Properties

PropertyDescriptionSetter Method
ArcHeightVertical diameter of the arc at the four corners of rectanglesetArcHeight(Double height)
ArcWidthHorizontal diameter of the arc at the four corners of the rectanglesetArcWidth(Double Width)
HeightDefines the height of the rectanglesetHeight(Double height)
WidthDefines the width of the rectanglesetWidth(Double width)
XX coordinate of the upper left cornersetX(Double X-value)
YY coordinate of the upper left cornersetY(Double( Y-value)

Example 1:

Output:


JavaFX Rectangle Output

Rounded Corner Rectangle

We can make the corners of the rectangle round by just calling the instance setter methods setArcHeight() and setArcWidth(). It sets the height and width of the arc at the corners of Rectangle. The following example implements Rounded corner rectangle.

Example:

Output:


JavaFX Rectangle Rounded Corner Output
Next TopicJavaFX Ellipse




Latest Courses