java - Swing paint issue -
i have custom scrollbarui paint both thumb , track of scrollbar. when scrolling keeps lines below don't want. :
painting code below:
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); }
you need use
g.drawroundrect(..., thumbbounds.height - 1, 2, 2)
instead of
g.drawroundrect(..., thumbbounds.height, 2, 2)
the bottom edges of drawroundrect(x,y,width,height,arcw,arch)
@ y + height
, bottom edges of repaint(thumbbounds)
@ thumbbounds.y + thumbbounds.height - 1
. 1px line remain free of repaint.
Comments
Post a Comment