No LayoutManager: Absolute positioning : No Layout « Swing « Java Tutorial






To absolute positioning components, passing null to the setLayout method of a container.

No LayoutManager: Absolute positioning
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class NoLayoutTest extends JFrame {

  public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("NoLayout Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(null);
    JLabel label = new JLabel("First Name:");
    label.setBounds(20, 20, 100, 20);
    JTextField textField = new JTextField();
    textField.setBounds(124, 25, 100, 20);
    frame.add(label);
    frame.add(textField);
    frame.setSize(300, 100);
    frame.setVisible(true);
  }
}








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