Example usage for javax.swing JPanel setComponentZOrder

List of usage examples for javax.swing JPanel setComponentZOrder

Introduction

In this page you can find the example usage for javax.swing JPanel setComponentZOrder.

Prototype

public void setComponentZOrder(Component comp, int index) 

Source Link

Document

Moves the specified component to the specified z-order index in the container.

Usage

From source file:Main.java

public Main() {
    super("Test");
    setSize(200, 200);/*from w w  w  .j  av  a  2s. c o m*/

    JPanel panel = new JPanel();
    setContentPane(panel);

    JButton button1 = new JButton("Button 1");
    JButton button2 = new JButton("Button 2");
    JButton button3 = new JButton("Button 3");

    button1.setBounds(10, 10, 100, 40);
    button2.setBounds(5, 5, 100, 30);
    button3.setBounds(15, 15, 150, 40);

    panel.setLayout(null);

    panel.add(button1);
    panel.add(button2);
    panel.add(button3);

    panel.setComponentZOrder(button1, 1);
    panel.setComponentZOrder(button2, 0);
    panel.setComponentZOrder(button3, 2);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}