void (Graphics2D g, int xStart, int xEnd, int y) { Shape oldClip = g.getClip(); final int startPosCorrection = xStart % WIDTH == WIDTH - 1 ? 1 : 0; final int dotX0 = (xStart / WIDTH + startPosCorrection) * WIDTH; // draw lines in common phase final int width = ((xEnd - dotX0 - 1) / WIDTH + 1) * WIDTH; // always paint whole dot final Rectangle rectangle = new Rectangle(dotX0, y, width, HEIGHT); final Rectangle lineClip = oldClip != null ? oldClip.getBounds().intersection(rectangle) : rectangle; if (lineClip.isEmpty()) return; Composite oldComposite = g.getComposite(); try { g.setComposite(AlphaComposite.SrcOver); g.setClip(lineClip); StartupUiUtil.drawImage(g, myImage, dotX0, y, null); } finally { g.setComposite(oldComposite); g.setClip(oldClip); } }