if (x + maxWidth > clipRect.width) {
if (x + maxWidth > getWidth()) {
    public void paint(Graphics g) {        Rectangle clipRect = g.getClipBounds();        int x = 0, y = 0;        g.setColor(Color.white);        g.fillRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);        ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,                                         RenderingHints.VALUE_ANTIALIAS_ON);        g.setColor(Color.black);        if (brushes.indexOf(selectedBrush) > 0) {            int index = brushes.indexOf(selectedBrush);            int brushesInRow = getWidth() / maxWidth;            int bx = index % brushesInRow;            int by = index / brushesInRow;            g.drawRect(bx * maxWidth, by * maxWidth, maxWidth, maxWidth);        }        // DRAW THE STANDARD SIZES        Iterator itr = brushes.iterator();        while (itr.hasNext()) {            Brush b = (Brush) itr.next();            Rectangle bb = b.getBounds();            b.paint(g,                    x + ((maxWidth / 2) - bb.width / 2),                    y + ((maxWidth / 2) - bb.width / 2));            x += maxWidth;            if (x + maxWidth > clipRect.width) {                x = 0;                y += maxWidth;            }        }    }