JLayeredPane: add(Component comp, Object constraints) : JLayeredPane « javax.swing « Java by API






JLayeredPane: add(Component comp, Object constraints)

 


import java.awt.Color;

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

public class Main extends JFrame {
  public Main() {
    super("");
    setSize(570, 400);
    getContentPane().setBackground(new Color(244, 232, 152));

    getLayeredPane().setOpaque(true);

    JButton[] frames = new JButton[5];
    for (int i = 0; i < 5; i++) {
      frames[i] = new JButton("InnerFrame " + i);
      frames[i].setBounds(50 + i * 20, 50 + i * 20, 200, 200);
      getLayeredPane().add(frames[i]);
    }
    super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
  }

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

   
  








Related examples in the same category

1.JLayeredPane.DEFAULT_LAYER
2.JLayeredPane.PALETTE_LAYER
3.JLayeredPane.POPUP_LAYER
4.JLayeredPane: getAccessibleContext()