Java Documentation

Swing Layout Managers

Layouts decide where each component goes in your window. Swing uses layout managers like FlowLayout, GridLayout, GridBagLayout, and BorderLayout to automatically arrange components.

Before layouts: understand components

If you have not yet studied the basic Swing components (JFrame, JPanel, buttons, labels, text fields), go through the components section first. The layout managers here will then make much more sense.

Common Swing layout managers

Each layout manager arranges components in a different way. Use these cards to jump into examples and line-by-line explanations.

Why layout managers matter

Instead of giving pixel-perfect positions, Swing lets layout managers adapt your UI when the window is resized, fonts change, or components are added/removed. For exams, you mostly need to recognize and write small programs using each manager.