public Image createImage(int width,
                         int height)
Creates an off-screen drawable image to be used for double buffering. Parameters:
width - the specified width
height - the specified height 
Returns:
an off-screen drawable image, which can be used for double buffering. The return value may be null if the component is not displayable. This will always happen if GraphicsEnvironment.isHeadless() returns true
public boolean isDisplayable()
Determines whether this component is displayable. A component is displayable when it is connected to a native screen resource. 
A component is made displayable either when it is added to a displayable containment hierarchy or when its containment hierarchy is made displayable. A containment hierarchy is made displayable when its ancestor window is either packed or made visible. A component is made undisplayable either when it is removed from a displayable containment hierarchy or when its containment hierarchy is made undisplayable. A containment hierarchy is made undisplayable when its ancestor window is disposed. 
Returns:
true if the component is displayable, false otherwise

解决方案 »

  1.   

    首先谢谢楼上的
    但不是很懂楼上说得我想在JFrame上绘画,由于要使用双缓冲,所以调用this.createImage创建离屏表面
    A component is displayable when it is connected to a native screen resource. 
    是否只能用awt的控件.createImage才不返回null?再请朋友们
      

  2.   

    难道用awt的createImage在你没有画图前不返回null吗?
    不会吧,好象都是null吧
    一般都是Image i=createImage(300,500);
            Graphics g=i.getGraphics();
            g.drawxxxx();
            
      

  3.   

    to xlys714(海哑) :
    Image i=createImage(300,500); 就是这句话出问题,i返回的是null呀~!
      

  4.   

    One last way of creating a buffered image is using Component.createImage(). This method can be used only if the component is visible on the screen. Also, this method returns buffered images that do not support transparent pixels. 
        BufferedImage bimage = (BufferedImage)component.createImage(width, height);
        if (bimage == null) {
            // The component is not visible on the screen
        }这说明你必须在一个屏幕上可见的component对象上调用该方法。
      

  5.   

    to chunhuachan(chunhua)
    可见的component对象?
    可见呀,我的button,Panel都是可见的呀,但都返回null你可以写个程序亲自试试看。