gpt4 book ai didi

java - Swing 油漆问题

转载 作者:搜寻专家 更新时间:2023-11-01 03:53:35 25 4
gpt4 key购买 nike

我有一个自定义的 scrollbarUI,我绘制了滚动条的拇指和轨道。但是当滚动时,它会保留一些我不想要的行,如下所示。 :

enter image description here

绘画代码如下:

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);
}

最佳答案

你需要使用

g.drawRoundRect(..., thumbBounds.height - 1, 2, 2) 

代替

g.drawRoundRect(..., thumbBounds.height, 2, 2)

drawRoundRect(x,y,width,height,arcW,arcH) 的底部边缘位于 y + height,但 的底部边缘>repaint(thumbBounds) 位于 thumbBounds.y + thumbBounds.height - 1。所以 1px 线保持免费重绘。

关于java - Swing 油漆问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16535306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com