Images in JInternalFrame

Hi,

I have a JInternalFrame that I would like to display an image it, and then have components on that.

I have tried to put a bufferedImage in a class that I extend the JInternalFrame from, then, override the paintComponent.

Here is a line from that function (this is basically the only thing in it):

g2d.drawImage(background, 0, 0, this);

where this is the class of the extended JInternalFrame.

When I run this, it does not draw anything on the frame. I have also tried to replace the two 0’s with the position of the JInternalFrame, that did not work either.

Thanks for any help.

Try creating a class like ‘DrawingPanel’ or similar that subclasses JPanel. Do your drawing from within this class (in the paintComponent method still) and either set an instance of it as your JInternalFrame’s content pane or add it to the content pane. The other thing you may try is adding a println to the paintComponent method where you are drawing now to see if it’s even being called so that you can narrow down the origins of the problem a bit. If it’s not getting called you could look in the Java api to find out what causes a JInternalFrame’s paintComponent method to be called.

It is being called, but no image is being made.

I also tried to draw shapes in there, like a rectangle, but that does not work either.

BUT, your other idea with the drawing panel works fine.

Thanks.