Problem with refreshing bufferedimage object

From DB2 I get one BLOB, and I print this BLOB on JPanel (blob is BuffferedImage object). When the screen is minimised or another window comes on top of the main window, my image disappear. Why? I know, that I must override paintComponents() method, but I dont know how to do that. Any sugestions?

My printing code:

public void drawFoto(BufferedImage photo)

{

double skalaZdjW = 0;

double skalaZdjH = 0;

double skalaPodpisW = 0;

double skalaPodpisH = 0;

int skalaW = 0;

int skalaH = 0;

int skalaW1 = 0;

int skalaH1 = 0;

//scaling photo to panel dimensions

if (photo!=null)

{

skalaZdjW = (double)panFoto.getWidth()/

(double)photo.getWidth();

skalaZdjH = (double)panFoto.getHeight()/

(double)photo.getHeight();

if( skalaZdjW>skalaZdjH)

{

skalaH1 = (int)(photo.getHeight()*skalaZdjH);

skalaW1 = (int)(photo.getWidth()*skalaZdjH);

}

else

{

skalaH1 = (int)(photo.getHeight()*skalaZdjW)-5;

skalaW1 = (int)(photo.getWidth()*skalaZdjW)-5;

}

ImageObserver obs = null;

panFoto.getGraphics().clearRect(1,1,panFoto.getWidth(),panFoto.getHeight());

panFoto.getGraphics().drawImage(photo,5,20,skalaW1,skalaH1,obs);

}

}

best regards

C.

[1341 byte] By [Czareka] at [2007-10-3 8:36:03]
# 1

I think that the only thing you must do is create a public void paint(Graphics g) method and move the code inside changing

panFoto.getGraphics().clearRect(1,1,panFoto.getWidth(),panFoto.getHeight());

panFoto.getGraphics().drawImage(photo,5,20,skalaW1,skalaH1,obs);

to

g.clearRect(1,1,panFoto.getWidth(),panFoto.getHeight());

g.drawImage(photo,5,20,skalaW1,skalaH1,obs);

Regards,

Eduardo

Message was edited by:

Reise: Just formatted it better.

Reisea at 2007-7-15 3:43:41 > top of Java-index,Desktop,Core GUI APIs...
# 2

Use the code formatting tags when posting code so the code is readable.

> I know, that I must override paintComponents() method, but I dont know how to do that. Any sugestions?

Did you search the forum for examples? Using "paintcomponent" as the keyword will find posting with example code.

camickra at 2007-7-15 3:43:41 > top of Java-index,Desktop,Core GUI APIs...