绘制矩形边框厚度 [英] Draw rectangle border thickness

查看:130
本文介绍了绘制矩形边框厚度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能做绘制一个矩形,在一个简单的方法给定的边框厚度?

Is it possible to do draw a rectangle with a given border thickness in an easy way?

推荐答案

如果您是在的的Graphics2D 对象,你可以使用 setStroke()方法:

If you are drawing on a Graphics2D object, you can use the setStroke() method:

Graphics2D g2;
double thickness = 2;
Stroke oldStroke = g2.getStroke();
g2.setStroke(new BasicStroke(thickness));
g2.drawRect(x, y, width, height);
g2.setStroke(oldStroke);

如果这是正在上Swing组件完成,你被通过了图形对象,你可以把它向下转换到的Graphics2D

If this is being done on a Swing component and you are being passed a Graphics object, you can downcast it to a Graphics2D.

Graphics2D g2 = (Graphics2D) g;

这篇关于绘制矩形边框厚度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆