首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swing paint问题

Swing paint问题
EN

Stack Overflow用户
提问于 2013-05-14 12:47:09
回答 1查看 151关注 0票数 4

我有一个自定义的scrollbarUI,我绘制了滚动条的拇指和轨迹。但在滚动时,它会保留一些我不想要的行。:

绘制代码如下:

代码语言:javascript
复制
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gradient = new GradientPaint(new Point(thumbBounds.x, thumbBounds.y), gray, new          Point(thumbBounds.x + width, thumbBounds.y), white);

    g.setColor(white);
    g.fillRoundRect(thumbBounds.x + 1, thumbBounds.y + 1, thumbBounds.width - 3, thumbBounds.height - 1, 2, 2);

    g2d.setPaint(gradient);
    g2d.fillRoundRect(thumbBounds.x + 2, thumbBounds.y + 2, thumbBounds.width - 4, thumbBounds.height - 3, 3, 3);

    //Draw middle lines:
    if ((getMinimumThumbSize().height + 10) < thumbBounds.height) {
        g.setColor(new Color(167, 167, 167));
        int w = ((thumbBounds.width > 16) ? 8 : (int) ((thumbBounds.width / 2.0) + 0.5));
        int x = (thumbBounds.width > 0) ? (thumbBounds.x + ((thumbBounds.width - w) / 2) - 1) : thumbBounds.x;

        g.drawLine(x, (thumbBounds.y + (thumbBounds.height / 2) - 3), (x + w), (thumbBounds.y + (thumbBounds.height / 2) - 3));
        g.drawLine(x, (thumbBounds.y + (thumbBounds.height / 2) - 1), (x + w), (thumbBounds.y + (thumbBounds.height / 2) - 1));
        g.drawLine(x, (thumbBounds.y + (thumbBounds.height / 2) + 1), (x + w), (thumbBounds.y + (thumbBounds.height / 2) + 1));
    }

    g.setColor(color_1);
    g.drawRoundRect(thumbBounds.x, thumbBounds.y, thumbBounds.width - 2, thumbBounds.height, 2, 2);
}
EN

回答 1

Stack Overflow用户

发布于 2015-04-24 16:29:23

您需要使用

代码语言:javascript
复制
g.drawRoundRect(..., thumbBounds.height - 1, 2, 2) 

而不是

代码语言:javascript
复制
g.drawRoundRect(..., thumbBounds.height, 2, 2)

drawRoundRect(x,y,width,height,arcW,arcH)的底边位于y + height,但repaint(thumbBounds)的底边位于thumbBounds.y + thumbBounds.height - 1。所以1px的线条没有重绘。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16535306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档