BasicStroke class defines a basic set of rendering
attributes for the outlines of graphics primitives, which are rendered
with a Graphics2D object that has its Stroke attribute set to
this BasicStroke.
The rendering attributes defined by BasicStroke describe
the shape of the mark made by a pen drawn along the outline of a
Shape and the decorations applied at the ends and joins of
path segments of the Shape.
These rendering attributes include:
SEG_CLOSE
for more information on the CLOSE segment.
The three different decorations are: CAP_BUTT,
CAP_ROUND, and CAP_SQUARE.
SEG_CLOSE.
The three different decorations are: JOIN_BEVEL,
JOIN_MITER, and JOIN_ROUND.
Shape
argument. When a Graphics2D object uses a
Stroke object to redefine a path during the execution
of one of its draw methods, the geometry is supplied
in its original form before the Graphics2D transform
attribute is applied. Therefore, attributes such as the pen width
are interpreted in the user space coordinate system of the
Graphics2D object and are subject to the scaling and
shearing effects of the user-space-to-device-space transform in that
particular Graphics2D.
For example, the width of a rendered shape's outline is determined
not only by the width attribute of this BasicStroke,
but also by the transform attribute of the
Graphics2D object. Consider this code:
Assuming there are no other scaling transforms added to the// sets the Graphics2D object's Transform attribute g2d.scale(10, 10); // sets the Graphics2D object's Stroke attribute g2d.setStroke(new BasicStroke(1.5f));
Graphics2D object, the resulting line
will be approximately 15 pixels wide.
As the example code demonstrates, a floating-point line
offers better precision, especially when large transforms are
used with a Graphics2D object.
When a line is diagonal, the exact width depends on how the
rendering pipeline chooses which pixels to fill as it traces the
theoretical widened outline. The choice of which pixels to turn
on is affected by the antialiasing attribute because the
antialiasing rendering pipeline can choose to color
partially-covered pixels.
For more information on the user space coordinate system and the
rendering process, see the Graphics2D class comments.
Graphics2D
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| public static final int | CAP_BUTT
Ends unclosed subpaths and dash segments with no added decoration. |
| public static final int | CAP_ROUND
Ends unclosed subpaths and dash segments with a round decoration that has a radius equal to half of the width of the pen. |
| public static final int | CAP_SQUARE
Ends unclosed subpaths and dash segments with a square projection that extends beyond the end of the segment to a distance equal to half of the line width. |
| pack-priv float[] | |
| pack-priv float | |
| pack-priv int | |
| public static final int | JOIN_BEVEL
Joins path segments by connecting the outer corners of their wide outlines with a straight segment. |
| public static final int | JOIN_MITER
Joins path segments by extending their outside edges until they meet. |
| public static final int | JOIN_ROUND
Joins path segments by rounding off the corner at a radius of half the line width. |
| pack-priv float | |
| pack-priv float |
| Access | Constructor and Description |
|---|---|
| public | BasicStroke(float
the width of this width, int BasicStroke. The
width must be greater than or equal to 0.0f. If width is
set to 0.0f, the stroke is rendered as the thinnest
possible line for the target device and the antialias
hint setting.the decoration of the ends of a cap, int BasicStrokethe decoration applied where path segments meet join, float the limit to trim the miter join. The miterlimit
must be greater than or equal to 1.0f. miterlimit, float[] the array representing the dashing pattern dash, float the offset to start the dashing pattern dash_phase)Constructs a new |
| public | BasicStroke(float
the width of the width, int BasicStrokethe decoration of the ends of a cap, int BasicStrokethe decoration applied where path segments meet join, float the limit to trim the miter join miterlimit)Constructs a solid |
| public | BasicStroke(float
the width of the width, int BasicStrokethe decoration of the ends of a cap, int BasicStrokethe decoration applied where path segments meet join)Constructs a solid |
| public | BasicStroke(float
the width of the width)BasicStrokeConstructs a solid |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Shape | Returns: theShape of the stroked outline.the s)Shape boundary be strokedImplements java. Returns a |
| public boolean | Returns: true if the width, join, cap, miter limit, dash, and
dash phase are the same for both objects;
false otherwise.the specified object to compare to this
obj)BasicStrokeOverrides java. Tests if a specified object is equal to this |
| public float[] | Returns: the dash array.Returns the array representing the lengths of the dash segments. |
| public float | |
| public int | Returns: the end cap style of thisBasicStroke as one
of the static int values that define possible end cap
styles.Returns the end cap style. |
| public int | Returns: the line join style of theBasicStroke as one
of the static int values that define possible line
join styles.Returns the line join style. |
| public float | |
| public float | Returns: the limit of miter joins of theBasicStroke.Returns the limit of miter joins. |
| public int | Returns: a hash code for this stroke.Overrides java. Returns the hashcode for this stroke. |
| cap | back to summary |
|---|---|
| pack-priv int cap | |
| CAP_BUTT | back to summary |
|---|---|
| public static final int CAP_BUTT Ends unclosed subpaths and dash segments with no added decoration. | |
| CAP_ROUND | back to summary |
|---|---|
| public static final int CAP_ROUND Ends unclosed subpaths and dash segments with a round decoration that has a radius equal to half of the width of the pen. | |
| CAP_SQUARE | back to summary |
|---|---|
| public static final int CAP_SQUARE Ends unclosed subpaths and dash segments with a square projection that extends beyond the end of the segment to a distance equal to half of the line width. | |
| dash | back to summary |
|---|---|
| pack-priv float[] dash | |
| dash_phase | back to summary |
|---|---|
| pack-priv float dash_phase | |
| join | back to summary |
|---|---|
| pack-priv int join | |
| JOIN_BEVEL | back to summary |
|---|---|
| public static final int JOIN_BEVEL Joins path segments by connecting the outer corners of their wide outlines with a straight segment. | |
| JOIN_MITER | back to summary |
|---|---|
| public static final int JOIN_MITER Joins path segments by extending their outside edges until they meet. | |
| JOIN_ROUND | back to summary |
|---|---|
| public static final int JOIN_ROUND Joins path segments by rounding off the corner at a radius of half the line width. | |
| miterlimit | back to summary |
|---|---|
| pack-priv float miterlimit | |
| width | back to summary |
|---|---|
| pack-priv float width | |
| BasicStroke | back to summary |
|---|---|
| public BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) Constructs a new
| |
| BasicStroke | back to summary |
|---|---|
| public BasicStroke(float width, int cap, int join, float miterlimit) Constructs a solid
| |
| BasicStroke | back to summary |
|---|---|
| public BasicStroke(float width, int cap, int join) Constructs a solid
| |
| BasicStroke | back to summary |
|---|---|
| public BasicStroke(float width) Constructs a solid
| |
| BasicStroke | back to summary |
|---|---|
| public BasicStroke() Constructs a new | |
| createStrokedShape | back to summary |
|---|---|
| public Shape createStrokedShape(Shape s) Implements java. Returns a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Tests if a specified object is equal to this
| |
| getDashArray | back to summary |
|---|---|
| public float[] getDashArray() Returns the array representing the lengths of the dash segments.
Alternate entries in the array represent the user space lengths
of the opaque and transparent segments of the dashes.
As the pen moves along the outline of the
| |
| getDashPhase | back to summary |
|---|---|
| public float getDashPhase() Returns the current dash phase. The dash phase is a distance specified in user coordinates that represents an offset into the dashing pattern. In other words, the dash phase defines the point in the dashing pattern that will correspond to the beginning of the stroke.
| |
| getEndCap | back to summary |
|---|---|
| public int getEndCap() Returns the end cap style.
| |
| getLineJoin | back to summary |
|---|---|
| public int getLineJoin() Returns the line join style.
| |
| getLineWidth | back to summary |
|---|---|
| public float getLineWidth() Returns the line width. Line width is represented in user space,
which is the default-coordinate space used by Java 2D. See the
| |
| getMiterLimit | back to summary |
|---|---|
| public float getMiterLimit() Returns the limit of miter joins.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns the hashcode for this stroke.
| |