Class Shape

java.lang.Object
javafx.scene.Node
javafx.scene.shape.Shape
All Implemented Interfaces:
Styleable, EventTarget
Direct Known Subclasses:
Arc, Circle, CubicCurve, Ellipse, Line, Path, Polygon, Polyline, QuadCurve, Rectangle, SVGPath, Text

public abstract class Shape extends Node
The Shape class provides definitions of common properties for objects that represent some form of geometric shape. These properties include:
  • The Paint to be applied to the fillable interior of the shape (see setFill).
  • The Paint to be applied to stroke the outline of the shape (see setStroke).
  • The decorative properties of the stroke, including:
    • The width of the border stroke.
    • Whether the border is drawn as an exterior padding to the edges of the shape, as an interior edging that follows the inside of the border, or as a wide path that follows along the border straddling it equally both inside and outside (see StrokeType).
    • Decoration styles for the joins between path segments and the unclosed ends of paths.
    • Dashing attributes.

An application should not extend the Shape class directly. Doing so may lead to an UnsupportedOperationException being thrown.

Interaction with coordinate systems

Most nodes tend to have only integer translations applied to them and quite often they are defined using integer coordinates as well. For this common case, fills of shapes with straight line edges tend to be crisp since they line up with the cracks between pixels that fall on integer device coordinates and thus tend to naturally cover entire pixels.

On the other hand, stroking those same shapes can often lead to fuzzy outlines because the default stroking attributes specify both that the default stroke width is 1.0 coordinates which often maps to exactly 1 device pixel and also that the stroke should straddle the border of the shape, falling half on either side of the border. Since the borders in many common shapes tend to fall directly on integer coordinates and those integer coordinates often map precisely to integer device locations, the borders tend to result in 50% coverage over the pixel rows and columns on either side of the border of the shape rather than 100% coverage on one or the other. Thus, fills may typically be crisp, but strokes are often fuzzy.

Two common solutions to avoid these fuzzy outlines are to use wider strokes that cover more pixels completely - typically a stroke width of 2.0 will achieve this if there are no scale transforms in effect - or to specify either the StrokeType.INSIDE or StrokeType.OUTSIDE stroke styles - which will bias the default single unit stroke onto one of the full pixel rows or columns just inside or outside the border of the shape.

Since:
JavaFX 2.0