by Dinesh Thakur Category: Swing

A layered pane is a Swing container which is used to hold the various components using the concept of layers. The components present in the upper layer overlaps the components present in the lower layer. The layered pane is created using the JLayeredPane class. the only constructor of this class is JLayeredPane ().

Example: A program to demonstrate the use of JLayeredPane class.

import java.awt.*;

import javax.swing.*;

class LayerExample extends JApplet


    JFrame jf ;

    JLayeredPane LPane;

    JButton first, second, third;

    LayerExample ()


         jf =new JFrame("Layered Pane Example");

         LPane =new JLayeredPane();

         jf.getContentPane() .add(LPane);

         first= new JButton("First");



         second= new JButton("Second");



         third= new JButton("Third");



         LPane.add(first, new Integer(3));

         LPane.add(second, new Integer(2));

         LPane.add(third, new Integer(1));


         jf.setSize (400,300) ;



         public static void main(String args[])


            LayerExample le= new LayerExample();



The output of the program is shown in Figure

              Layered Panes Java Swing Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles