Not sure if this is the right place to put this as it's my first post, so if it's not I apologize.

I'm wondering if there is a way to put an image into the background of my applet. I've searched all over the place and just can't seem to be able to find.

My problem is that I need buttons to show up over the image, without me having to wave my curser over it to bring it to the top. So yes I know I can put an image on a label, but when I do it ends up covering my buttons, even when I add it to the applet first.

Any help would be appreciated.

7 Years
Discussion Span
Last Post by Dudesup

You can subclass JPanel to paint your image as it's background. Anything else you put on that panel should show up normally.

class ImagePanel extends JPanel {

        Image img;

        public ImagePanel() {
            img = new ImageIcon(getClass().getResource("images/blackX.gif")).getImage();

        public void paintComponent(Graphics g) {
            g.drawImage(img, 0, 0, getWidth(), getHeight(), this);

Well it sort of worked. The image showed up, but it is still covering the buttons for some unfathomable reason.

Have any idea on what might be wrong?


OK, well that got all the buttons to show up which is awsome. But I need to be able to move them into different spots. Can I do that within the Label?

I know I can set the alignment and that but I only have set it to things like CENTER.


Nice, thanks for this. Helps alot. Well I have alot of reading in front of me.

Thanks again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.