Swing 画虚线示例代码

阅读更多

float[] dash1 = { 3.0f, 3.0f };
  BasicStroke s = new BasicStroke(profileLineWidth, BasicStroke.CAP_BUTT,
    BasicStroke.JOIN_MITER, 10.0f, dash1, 3.0f);
  g2.setStroke(s);

  g2.setPaint(Color.RED);
  maLadderPath.reset();
  double startX = dP[3].getX();
  double startY = dP[3].getY();

  maLadderPath.moveTo(startX, startY);
  for (int i = 0; i < xSliceMAValueList.size(); i++) {
   double endY = startY
     + xSliceMAValueList.get(i).getSliceThicknessValue();
   maLadderPath.lineTo(startX + xSliceMAValueList.get(i).getMaValue()
     - 5, startY);
   maLadderPath.lineTo(startX + xSliceMAValueList.get(i).getMaValue()
     - 5, endY);
   startY = endY;
  }
  maLadderPath.lineTo(startX, startY);
  g2.draw(maLadderPath);

你可能感兴趣的:(SWING,GRAPHICS2D)