java - Eclipse WindowBuilder: Ignore runtime paint() code -
this question has answer here:
- what nullpointerexception, , how fix it? 12 answers
one of jpanels in swing gui designing uses awt graphics drawing figures drawable @ runtime. eclipse windowbuilder no longer wants draw of swing gui there null pointer exceptions in awt paint code. note not generic question null pointer exceptions. specific windowbuilder , how handle code doesn't make sense in context of windowbuilder. there method ignore awt paint code if windowbuilder trying interpret 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 particular example, previewpanel embedded inside of overall swing gui working in windowbuilder , businessclass.object initialized @ runtime (main invokes initialization of businessclass, not gui itself). have shown 1 example, there many other cases call painting code of runtime object or list of objects need drawn awt graphics.
i found workaround wrapping run time code in null pointer check against businessclass singleton. windowbuilder won't pass check, code skipped over. it's dirty solution. hoping compile flags or whatnot.
wiki
Comments
Post a Comment