static void paintTiledBackground_centered(Component c, Graphics g, BufferedImage image) { int w = c.getWidth(); int h = c.getHeight(); int tw = image.getWidth(), th = image.getHeight(); // center of tile should be in center of image int shiftX = (w-tw)/2, shiftY = (h-th)/2; int y1 = mod(shiftY-1, th)-th+1; for (int x = mod(shiftX-1, tw)-tw+1; x < w; x += tw) for (int y = y1; y < h; y += th) g.drawImage(image, x, y, c); }