0

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.

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Dudesup
0

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() {
            super();
            img = new ImageIcon(getClass().getResource("images/blackX.gif")).getImage();
        }

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

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?

0

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.

0

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.