createImage() null.
I finally make the progressBar using Graphics 2D.
The reason why I create ProgressBar using Graphics 2D is color changes in XP theme. which doesn't work.
What I want is :
show this progressbar added to Jpanel.
But, in JFrame, it shows but in JFrame added to JPanel, it doesn't show. I used createImage(int w, int h).I heard off-Image issue, which I don't understand. In Javadoc,
__
Returns:
an off-screen drawable image, which can be used for double buffering. The return value may be null if the component isnot displayable. This will always happen if GraphicsEnvironment.isHeadless() returns true.
_
So, what decides displayable or not. Further Graphics Enviornment.isHeadliess() -> true.
How can I make this isHeadless -> false so that it can be displayable so that the progressBar I draw using createImage can be shown.
Please let me know. This is a bazaar phenomenon.
__
This is code for the test.
package Daemon;
import java.awt.*;
import javax.swing.JPanel;
class HIextends Canvas
{
ImagedrawImg;
GraphicsdrawGr;
intxprev, yprev;
publicvoid paint(Graphics g)
{
update(g);
}
publicvoid update(Graphics g){
Dimension d = size();
if( drawImg ==null ){
drawImg= createImage(100,100);
drawGr= drawImg.getGraphics();
setBackground(Color.gray);
}
g.drawImage(drawImg, 0, 0,null);
}
publicboolean mouseDown(Event evt,int x,int y)
{
xprev = x;
yprev = y;
returntrue;
}
publicboolean mouseDrag(Event evt,int x,int y)
{
drawGr.drawLine(xprev, yprev, x, y);
xprev = x;
yprev = y;
repaint();
returntrue;
}
publicstaticvoid main(String args[]){
Frame f =new Frame();
// step 1. on top of panel
//JPanel thePanel = new JPanel();
//thePanel.add(new HI());
//f.add(thePanel);
// step 2. not on top of panel
f.add(new HI());
f.setSize(100,100); f.show();
}
}
step 1. doesn't work
step 2. does work.
It is so strange why...
Message was edited by:
PaulSheldonII_Screen

