如何去除“妊娠纹”在自定义按钮边框? [英] How to remove "stretch marks" on custom button border?

查看:89
本文介绍了如何去除“妊娠纹”在自定义按钮边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在按钮的 Graphics2D 对象上执行某些自定义绘画时,我得到以下结果:

When performing some custom painting on a button's Graphics2D object, I get the following results:

最左边的按钮是未锁定的其他是切换。如您所见,切换按钮具有这些白色妊娠纹。为什么会有这些?如何删除它们?

The leftmost button is untoggled and the other is toggled. As you can see, the toggled button has these white "stretch marks." Why are these there and how do I remove them?

以下是我用来绘制边框的代码:

And here is the code I use to draw the border:

// Draw border of button
if(!getModel().isSelected())
{
    g2.fillRoundRect(2, 2, getWidth() - 5, getHeight() - 5, ARC_WIDTH, ARC_HEIGHT);
    g2.setColor(Color.BLACK);
    g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, ARC_WIDTH, ARC_HEIGHT);
    g2.setColor(Color.WHITE);
    g2.drawRoundRect(1, 1, getWidth() - 3, getHeight() - 3, ARC_WIDTH, ARC_HEIGHT);
    g2.setColor(Color.WHITE);
    g2.drawRoundRect(2, 2, getWidth() - 5, getHeight() - 5, ARC_WIDTH, ARC_HEIGHT);
    g2.setColor(Color.BLACK);
    g2.drawRoundRect(3, 3, getWidth() - 7, getHeight() - 7, ARC_WIDTH, ARC_HEIGHT);
}
else
{
    g2.fillRoundRect(2, 2, getWidth() - 5, getHeight() - 5, ARC_WIDTH, ARC_HEIGHT);
    g2.setColor(Color.BLACK);
    g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, ARC_WIDTH, ARC_HEIGHT);
    g2.setColor(Color.BLACK);
    g2.drawRoundRect(1, 1, getWidth() - 3, getHeight() - 3, ARC_WIDTH, ARC_HEIGHT);
    g2.setColor(Color.BLACK);
    g2.drawRoundRect(2, 2, getWidth() - 5, getHeight() - 5, ARC_WIDTH, ARC_HEIGHT);
    g2.setColor(Color.BLACK);
    g2.drawRoundRect(3, 3, getWidth() - 7, getHeight() - 7, ARC_WIDTH, ARC_HEIGHT);
}


推荐答案

你为什么画这么多按钮周围的圆角矩形?
据我所知,正确的方法是在绘制你喜欢的边框时使用 setStroke() API。

Why are you drawing so many rounded rectangles around the button? As far as I can see, the correct way to do this would be to use setStroke() API while drawing the kind of border you like.

这篇关于如何去除“妊娠纹”在自定义按钮边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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