code: public static void colorButton( JButton button, Color color, Integer size ) {
          if (size == null)
              size = 15;
          BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
          Graphics2D gr = (Graphics2D) bi.getGraphics();
          gr.setColor(color);
          gr.fillRect(0, 0, size, size);
          gr.dispose();
  
          button.setIcon(new ImageIcon(bi));
      }
docs: Create an image to make a color picker button.
  
  @param button the button.
  @param color the color to set.
  @param size the optional size of the image.