Can't get JLayeredPane to work

Hi,
I'm trying to use the JLayeredPane as part of a large application, but I can't get a small example to work... What else do I need to set before I can see my JLabel?
package views;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
public class Test extends JFrame {
      * @param args
     public static void main(String[] args) {
          new Test();
     public Test()
          super("Test");
          this.setVisible(true);
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          this.setSize(new Dimension(200, 200));
          JLayeredPane pane = (JLayeredPane) this.add(new JLayeredPane());
          pane.add(new JLabel("Hello World"), new Integer(0));
          this.add(pane);
}Edited by: TheDauntless on Oct 24, 2009 12:55 PM

TheDauntless wrote:
Thanks, that seems to work. You're welcome.
I have a follow up question: How can I get my JLabel to take up the entire parents width & height?
I usually use a GridBagLayout (with fill=horizontal, weightx=1, heightx=1, gridx=0, gridy=0), but I can't always get it to work. Is there a better way to make sure the size is 100%x100% ?I know that I use GridBagLayout, but only sparingly and only when other layouts (including nested layouts) won't work. I think that there are several in this same camp. In your situation, you could easily just use a BorderLayout and add the JLabel BorderLayout.CENTER.

Similar Messages

Maybe you are looking for