One of the JPanels in a swing GUI I am designing uses AWT graphics for drawing figures that are only drawable at runtime. Eclipse WindowBuilder no longer wants to draw any of my swing GUI as there are now null pointer exceptions in the awt paint code. Note that this is not a generic question about null pointer exceptions. This is specific to WindowBuilder and how to handle code that doesn't make sense in the context of WindowBuilder. Is there a method by which I could ignore the awt paint code if WindowBuilder is trying to interpret my swing gui?
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
public class previewPanel extends JPanel {
private static final long serialVersionUID = 3787425749772291816L;
public final static int WIDTH = 918;
public final static int HEIGHT = 125;
public void paint(Graphics g) {
BufferedImage img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
Graphics gBuffer = img.getGraphics();
gBuffer.setColor(Color.WHITE);
gBuffer.fillRect(0, 0, WIDTH, HEIGHT);
businessClass.object.paint(gBuffer);
g.drawImage(img, 0, 0, this);
try {
Thread.sleep(20);
} catch (Exception e) {
}
repaint();
}
In this particular example, previewPanel is embedded inside of an overall swing gui I am working with in WindowBuilder and businessClass.object is only initialized at runtime (Main invokes the initialization of businessClass, not the gui itself). I have only shown one example, but there are many other cases where I call the painting code of a runtime object or list of objects that need to be drawn with awt graphics.