Java 矩形边框
我有一些由 矩形 类创建的形状,我想用粗边框包围它们。然而,Graphics 类中的方法drawRect 和drawOval 创建了一条细线作为形状的边框。我如何调整它们以便能够操纵边框线的粗细?如果这不可能或非常有效,那么在形状上分配可调整边框的另一种方法是什么?我需要 Rectangle2D 或 Graphics2D 吗?
之后,你知道如何将正方形边框的角度“圆化”,使其不那么尖锐吗?
I have some shapes created by class Rectangle and I want to surround them with a thick border. However the methods drawRect and drawOval form Graphics class create a thin line as the border of the shape. How can I adjust them so as me to able to manipulate the thickness of the border line? If this is not possible or quite effective, what is another way to assign an adjustable border on the shapes? May I need Rectangle2D or Graphics2D?
After that, do you know how I can “round” the angles of the border of a square so as not to be sharp?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要使边框更粗,请使用
Graphics2D.setStroke(...)
。要绘制“圆角”矩形,请使用Graphics.drawRoundRect(...)
。To make the border thicker, use
Graphics2D.setStroke(...)
. And to draw "rounded" rectangles, useGraphics.drawRoundRect(...)
.查看 Graphics2D 笔画:
Graphics2D.setStroke()
BasicStroke
如果一轮加入你的笔画不够柔软,看看
RoundRectangle2D
。Look into Graphics2D strokes:
Graphics2D.setStroke()
BasicStroke
If a round join in your stroke isn't soft enough, look into
RoundRectangle2D
.我实现了图标的自定义圆形。
1) 粗边框可以通过以下方式绘制:
2) 圆形可以通过以下方式绘制:
所有代码都在这里:
}
I implemented custom rounded shape for icons.
1) The thick border can be painted by :
2) Rounded shape could be painted by:
All code is here:
}