You are here:   HomeJava ProgrammingSwingJLayeredPane Java Swing Example
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");

         first.setBackground(Color.red);

         first.setBounds(50,30,100,100);

         second= new JButton("Second");

         second.setBackground(Color.yellow);

         second.setBounds(140,60,100,100);

         third= new JButton("Third");

         third.setBackground(Color.green);

         third.setBounds(230,90,100,100);

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

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

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

         jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);

         jf.setSize (400,300) ;

         jf.setVisible(true);

     }

         public static void main(String args[])

        {

            LayerExample le= new LayerExample();

        }

}

The output of the program is shown in Figure

              Layered Panes Java Swing Example





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes 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.



What's New and Popular





Popular Article