Hello Members,

I have a Class_A which extends a JPanel. This JPanel is inside of a JFrame. In Class_A, I have a series of images (stored in an ImageIcon array) and another image, let's call it Image_A, which is also a ImageIcon type. How do I make Image_A a background image for Class_A and also be able to show the series of images on top of this background?

If the above is not possible, can I make two classes (which extend from JPanel) and layer them on top of another and using the setOpaque(false) method?

I would be grateful for any help.

Thank you!

Recommended Answers

All 4 Replies

Hello Members,

Any comments/suggestions?

Thank you!

Well, all you need to do is paint on the panel.
So in the class that extends JPanel create the paintmethod

public void paintComponent(Graphics g) {
         super.paintComponent(g);
 Graphics2D g2d = (Graphics2D) g;

then simply draw onto the panel

g2d.drawImage(bgImage,0,0,null);
g2d.drawImage(character,0,0,null);

this will draw the background image first, then draw everything else above it.

Hello Akill and Sean,

Thank you!!

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.