This Java Swing tip illustrates a method of implementing buttons in different layers. Layers are implemented using the JLayeredPane class in the application. A layered pane is a Swing container that provides a third dimension for positioning components: depth, also known as Z order.

 import javax.swing.*;
import java.awt.Color;

public class SimpleLayers extends JFrame {
    public SimpleLayers() {
        super("LayeredPane Demonstration");
        setSize(200, 150);
        JLayeredPane lp = getLayeredPane();
        // Create 3 buttons
        JButton top = new JButton();
        top.setBounds(20, 20, 50, 50);
        JButton middle = new JButton();
        middle.setBounds(40, 40, 50, 50);
        JButton bottom = new JButton();
        bottom.setBounds(60, 60, 50, 50);
        // Place the buttons in different layers
        lp.add(middle, new Integer(2));
        lp.add(top, new Integer(3));
        lp.add(bottom, new Integer(1));
    public static void main(String[] args) {
        SimpleLayers sl = new SimpleLayers();