Setting individual pixels in a BufferedImage in Swing

You can use the method setRGB. This example goes through a loop painting each pixel of the BufferedImage individually.

Main.java:

import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
 
public class Main extends JFrame {
   private boolean firstTime = true;
   private BufferedImage bufferedImage;
 
   public Main() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(1);
         }
      }); 
   } 
 
   public void paint(Graphics graphics) {
      Graphics2D g2d = (Graphics2D) graphics;
  
      g2d.drawString("Please wait...", 100, 100);
      if (firstTime) {
         bufferedImage = (BufferedImage) createImage(getSize().width, getSize().height);
 
         int x=0, y=0;
         for (int r=0; r<=255; r+=4) {
            for (int g=0; g<=255; g+=4) {
               for (int b=0; b<=255; b+=4) {
                  x++; if (x>getSize().width) { y++; x = 0; }
                  Color c = new Color(r, g, b);
                  bufferedImage.setRGB(x, y, c.getRGB());
               }
            }
         }
 
         firstTime = false;
      }
 
      g2d.drawImage(bufferedImage, 0, 0, this);
   }
 
   public static void main(String []args) {
      Main main = new Main();
      main.setVisible(true);
      main.setSize(512, 512);
   }
}