Implement buttons at different layers : LayeredPane « Swing JFC « Java

Implement buttons at different layers


import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;

public class Main extends JFrame {
  public Main() {
    setSize(200, 150);
    JLayeredPane lp = getLayeredPane();
    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);

    lp.add(middle, new Integer(2));
    lp.add(top, new Integer(3));
    lp.add(bottom, new Integer(1));

  public static void main(String[] args) {
    new Main();


Related examples in the same category

1.A demonstration of the JLayeredPane classA demonstration of the JLayeredPane class
2.JLayeredPane SampleJLayeredPane Sample
3.Layered Panel demo 2Layered Panel demo 2
4.Layered Pane DemoLayered Pane Demo
5.LayeredPane Demo 2: Custom MDILayeredPane Demo 2: Custom MDI
6.LayeredPane Demo 3: Custom MDILayeredPane Demo 3: Custom MDI
7.LayeredPane Demo 4: Custom MDILayeredPane Demo 4: Custom MDI