Z Order : No Layout « Swing « Java Tutorial






Z Order
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ZOrder extends JPanel {

  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(new ZOrder());
    f.setSize(400, 300);
    f.setVisible(true);
  }

  public ZOrder() {
    setLayout(null);
    JButton first = new JButton("This button is added first");
    first.setBounds(20, 50, 200, 30);
    add(first);
    JButton second = new JButton("This button is added second");
    second.setBounds(120, 65, 200, 30);
    add(second);
  }

}








14.98.No Layout
14.98.1.No LayoutManager: Absolute positioningNo LayoutManager: Absolute positioning
14.98.2.Z OrderZ Order
14.98.3.Without layout manager, we position components using absolute values.
14.98.4.Laying Out Components Using Absolute Coordinates