public class BasicStroke extends java.lang.Object implements Stroke
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: // sets the Graphics2D object's Tranform attribute g2d.scale(10, 10); // sets the Graphics2D object's Stroke attribute g2d.setStroke(new BasicStroke(1.5f));Assuming there are no other scaling transforms added to the
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.
CSS example:
stroke {
class : "java.awt.BasicStroke(lineWidth,endCap,lineJoin,miterLimit,dashArray,dashPhase)";
dashArray[0] : "2.0";
dashArray[1] : "2.0";
dashPhase : "2.0";
endCap : "CAP_BUTT";
lineJoin : "JOIN_BEVEL";
lineWidth : "2.0";
miterLimit : "2.0";
}
Modifier and Type | Property and Description |
---|---|
java.lang.String |
class
Creates an instance of a BasicStroke . |
float[] |
dashArray
Represents the lengths of the dash segments. |
float |
dashPhase
The current dash phase. |
int |
endCap
The end cap style. |
int |
lineJoin
The line join style. |
float |
lineWidth
The line width is represented in user space, which is the default-coordinate space used by Java 2D. |
float |
miterLimit
The limit of miter joins of the BasicStroke . |
public java.lang.String class
BasicStroke
.
class : "java.awt.BasicStroke(lineWidth,endCap,lineJoin,miterLimit,dashArray,dashPhase)";
public float[] dashArray
dashArray[0] : "2.0";
dashArray[1] : "2.0";
public float dashPhase
dashPhase : "2.0";
public int endCap
endCap : "CAP_BUTT";
Allowed values: | ||
CAP_BUTT |
Ends unclosed subpaths and dash segments with no added decoration. | |
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 |
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. |
public int lineJoin
lineJoin : "JOIN_BEVEL";
Allowed values: | ||
JOIN_BEVEL |
Joins path segments by connecting the outer corners of their wide outlines with a straight segment. | |
JOIN_MITER |
Joins path segments by extending their outside edges until they meet. | |
JOIN_ROUND |
Joins path segments by rounding off the corner at a radius of half the line width. |
public float lineWidth
Graphics2D
class comments
for more information on the user space coordinate system.
lineWidth : "2.0";
public float miterLimit
BasicStroke
.
miterLimit : "2.0";
© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.