Hi guys
I am attempting to overlay images on top of a background image using the standard java utilities. See the pictures below...
I have code that seems to create the background image (can you verify that it really works?) And I have created an extension of JPanel that I use to display images (the class is called ImagePanel)
However, when the program launches, the JFrame is only showing the second image, which then gets moved around as the window is resized.
I'd like to have the window open initially with the background image taking up the entirety of the window's space. I'd then like to have the second image displayed on top, at the location that I specify.
import javax.swing.*;
import java.awt.*;
public class ImageTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().setLayout(null);
JPanel backgroundPanel = new JPanel();
ImageIcon backgroundImage = new ImageIcon("C:\\Documents and Settings\\Robert\\Desktop\\ClientServer\\Poker Table Art\\TableAndChairs.png");
JLabel background = new JLabel(backgroundImage);
background.setBounds(0, 0, backgroundImage.getIconWidth(), backgroundImage.getIconHeight());
frame.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
backgroundPanel.setOpaque(false);
frame.setContentPane(backgroundPanel);
ImagePanel button = new ImagePanel("C:\\Documents and Settings\\Robert\\Desktop\\ClientServer\\Poker Table Art\\button.png");
JPanel cardContainer = new JPanel(new FlowLayout());
frame.getContentPane().add(cardContainer);
cardContainer.add(button);
cardContainer.setBounds(100, 600, 200, 200);
frame.pack();
frame.setVisible(true);
}
}