Adding components to a layered pane

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anurag275125
    New Member
    • Aug 2009
    • 79

    Adding components to a layered pane

    Hello all...
    There is an example in my book about how to add components to the layered pane. But I can't understand few lines of that program. Here is the code--
    Code:
    import java.awt.*;
    import javax.swing.*;
    /* <applet
    code=layeredpane.class
    width=600
    height=600
    >
    </applet> */
    public class layeredpane extends JApplet
    {
    	JLayeredPane jlp=new JLayeredPane();
    	JLabel[] jl=new JLabel[6];
    	public void init()
    	{
    		setContentPane(jlp);
    		jlp.setLayout(null);
    		jl[0]=new JLabel("Content Layer");
    		jl[0].setBorder(BorderFactory.createEtchedBorder());
    		jlp.setLayer(jl[0],jlp.FRAME_CONTENT_LAYER.intValue());
    		jlp.add(jl[0]);
    		jl[1]=new JLabel("Default Layer");
    		jl[1].setBorder(BorderFactory.createEtchedBorder());
    		jlp.setLayer(jl[1],jlp.DEFAULT_LAYER.intValue());
    		jlp.add(jl[1]);
    		jl[2]=new JLabel("Palette Layer");
    		jl[2].setBorder(BorderFactory.createEtchedBorder());
    		jlp.setLayer(jl[2],jlp.PALETTE_LAYER.intValue());
    		jlp.add(jl[2]);
    		jl[3]=new JLabel("Modal Layer");
    		jl[3].setBorder(BorderFactory.createEtchedBorder());
    		jlp.setLayer(jl[3],jlp.MODAL_LAYER.intValue());
    		jlp.add(jl[3]);
    		jl[4]=new JLabel("Popup Layer");
    		jl[4].setBorder(BorderFactory.createEtchedBorder());
    		jlp.setLayer(jl[4],jlp.POPUP_LAYER.intValue());
    		jlp.add(jl[4]);
    		jl[5]=new JLabel("Drag Layer");
    		jl[5].setBorder(BorderFactory.createEtchedBorder());
    		jlp.setLayer(jl[5],jlp.DRAG_LAYER.intValue());
    		jlp.add(jl[5]);
    		for(int i=0;i<jl.length;i++)
    			jl[i].setBounds(40*i,40*i,100,60);
    	}
    }
    We can set where the component will be displayed with the setBounds method. So why we have to use setLayer method in this program? The program is working when we omit setLayer method from program.Can anyone explain the purpose of DEFAULT_LAYER, PALETTE_LAYER, MODAL_LAYER, POPUP_LAYER and DRAG_LAYER.

    thanks & regards
Working...