Jump to content
  • Advertisement
Sign in to follow this  
chosenkill6

JLabel inside JLayeredPane

This topic is 1943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to create a JLayeredPane and would like to put a JLabel containing a JButton inside on top of a background image. As far as I understand I am supposed to add the button to the panel and then add the panel to the layeredpane. Then I add an image to the layeredpane as well. Finally I add the layeredPane to the JFrame. The button is drawing fine but when I add the image panel it does not display. I apologize for posting my all my code, I know no one likes to read through some one else's code but I commented it as best as I could to make it a bit easier. I really have not been able to find a solution to this problem anywhere. Any help appreciated :)

 

My two classes:

GUIFrame - http://pastebin.com/7MAByuzj

BackgroundPanel - http://pastebin.com/3KUU82hg

Share this post


Link to post
Share on other sites
Advertisement
 @Override
        public void paintComponent(Graphics g){
                super.paintComponents(g);
                this.setVisible(true);
               
                g.drawImage(backgroundImage, 0, 0, window.getWidth(), window.getHeight(), null);
        }
The drawImage() call paints the background above panel children (super.paintComponents(g)), which seems blatantly wrong, but the real problem is probably add()ing two or three panels to the JFrame without specifying layout constraints, so that they visually replace each other at BorderLayout.CENTER.

N.B. Your JFrame has a built-in JLayeredPane, you probably don't need to build another.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!