Java Utililty Methods Draw Dashed Line

List of utility methods to do Draw Dashed Line

Description

The list of methods to do Draw Dashed Line are organized into topic(s).

Method

voiddrawDashedLine(Graphics2D graphics, double x1, double y1, double x2, double y2)
draws a dashed line in the specified graphics context.
Stroke oldStroke = graphics.getStroke();
Color oldColor = graphics.getColor();
graphics.setStroke(DASHED_STROKE_LINE);
graphics.setColor(GRAY);
graphics.draw(new Line2D.Double(x1, y1, x2, y2));
graphics.setStroke(oldStroke);
graphics.setColor(oldColor);
voiddrawDashedRect(Graphics g, int x, int y, int width, int height)
draw Dashed Rect
int vx, vy;
for (vx = x; vx < (x + width); vx += 2) {
    g.fillRect(vx, y, 1, 1);
    g.fillRect(vx, y + height - 1, 1, 1);
for (vy = y; vy < (y + height); vy += 2) {
    g.fillRect(x, vy, 1, 1);
    g.fillRect(x + width - 1, vy, 1, 1);
...
voiddrawDashedRect(Graphics g, int x, int y, int width, int height)
Draws a rectangle, simulating a dotted stroke by painting only every second pixel along the one-pixel thick edge.
int right = x + width - 1;
int bottom = y + height - 1;
for (int i = x; i <= right; i += 2) {
    g.drawLine(i, y, i, y);
    g.drawLine(i, bottom, i, bottom);
for (int i = y; i <= bottom; i += 2) {
    g.drawLine(x, i, x, i);
...
voiddrawDashedRect(Graphics2D graphics, Rectangle2D rectangle)
Draws a dashed rectangle in the graphics context, with an X through the middle.
Stroke oldStroke = graphics.getStroke();
graphics.setStroke(DASHED_STROKE_RECT);
graphics.draw(rectangle);
graphics.draw(
        new Line2D.Double(rectangle.getX(), rectangle.getY(), rectangle.getMaxX(), rectangle.getMaxY()));
graphics.draw(
        new Line2D.Double(rectangle.getX(), rectangle.getMaxY(), rectangle.getMaxX(), rectangle.getY()));
graphics.setStroke(oldStroke);
...