IllegalArgumentException: height (0) cannot be 0 or less

edited October 2013 in Programming Questions

I am using processing from within an Eclipse RCP application. The Applet is initialized as follow:

            public final class ChartComposite<T extends  PApplet> extends Composite {
                    private final T pApplet;
                    private final Frame frame;

                    public ChartComposite(T aPApplet,Composite parent,int style) {
                        pApplet = aPApplet;
                        setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
                        frame = SWT_AWT.new_Frame(this);
                        frame.setLayout(new BorderLayout());
                            frame.add(pApplet, BorderLayout.CENTER);

                    public void dispose() {

When the frame is resized to have a height of 0, I get the exception, eg.:

Exception in thread "Animation Thread" java.lang.IllegalArgumentException: Width (1216) and height (0) cannot be <= 0 at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source) at sun.awt.Win32GraphicsConfig.createCompatibleImage(Unknown Source) at processing.core.PGraphicsJava2D.allocate( at processing.core.PGraphicsJava2D.setSize( at processing.core.PApplet.resizeRenderer( at at Source)

I am trying to detect when the frame has a height of 0, to prevent the resizing, but this seems to be quite a mission. Any suggestions on how to stop the exception from happening?


  • My guess is that when you do pApplet.init(), the frame where you added the PApplet isn't rendered yet, ie. the SWT hasn't set it a size (and position) yet.
    So its dimensions are zero and PApplet takes these dimensions to define the size of its rendering, which is rejected.

    Perhaps you can delay the call to init() to a stage when the frame is rendered.

Sign In or Register to comment.