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.

Recommended Answers

All 6 Replies

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);
        }
    }

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?

Add the panel to the applet and then add the other components to that panel.

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.

You can place them wherever you want just as with any other container. How you do that will depend on which LayoutManager you set for the panel.
Laying Out Components Within A Container

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

Thanks again.

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.