How to set JFrame's LayeredPane?

Hello,eveyone!

I wat to set JFrame's LayeredPane by JFrame's setLayeredPane() method.

My code as follow:

import javax.swing.*;

import java.awt.*;

publicclass LayeredTest{

publicstaticvoid main(String[] args){

SwingUtilities.invokeLater(new Runnable(){

publicvoid run(){

new MyFrame().setVisible(true);

}

});

}

}

class MyFrameextends JFrame{

public MyFrame(){

super("LayeredTest");

setLayeredPane(new JLayeredPane());//this line, I want to set the LayeredPane myself;

//but it doesn't work.

JPanel panel =new JPanel();

panel.setPreferredSize(new Dimension(320,240));

panel.add(new JLabel("Label"));

panel.add(new JButton("Button"));

add(panel);

setDefaultCloseOperation(EXIT_ON_CLOSE);

pack();

}

}

But the application runs abnormality.

Any one tells me why and how to modify?

thanks!

Message was edited by:

Eastsun

[2163 byte] By [Eastsuna] at [2007-11-26 19:01:00]
# 1
The content pane of the JFrame should be added to the layered pane.When you set a new layered pane, it doesn't automatically do that.Add this after you add the new layered pane:layeredPane.add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
Rodney_McKaya at 2007-7-9 20:44:13 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thank you very much!
Eastsuna at 2007-7-9 20:44:13 > top of Java-index,Desktop,Core GUI APIs...