@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(background); g2d.fillRect(x, y, getIconWidth(), getIconHeight()); g2d.setColor(Color.WHITE); Dimension dim = getGridSize(); double stepX = getIconWidth() / dim.getWidth(); double stepY = getIconHeight() / dim.getHeight(); Iterator<LayoutConstraints> enumVal = constraints.keySet().iterator(); while (enumVal.hasNext()) { LayoutConstraints l = enumVal.next(); Rectangle2D rect = new Rectangle2D.Double(x + l.gridx * stepX, y + l.gridy * stepY, l.gridwidth * stepX, l.gridheight * stepY); Color color = l.getColor(); if (color != null) { g2d.setColor(color); g2d.fill(rect); g2d.setColor(Color.WHITE); } g2d.draw(rect); } }