Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


JLabel inside JLayeredPane


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 nitishk   Members   -  Reputation: 161

Like
0Likes
Like

Posted 26 March 2013 - 08:18 PM

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



Sponsor:

#2 LorenzoGatti   Crossbones+   -  Reputation: 2734

Like
0Likes
Like

Posted 27 March 2013 - 03:24 AM

 @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.
Produci, consuma, crepa




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS