Java Swing Tutorials - Herong's Tutorial Examples
∟Layout of Components in a Container
This chapter provides tutorial notes and example codes on component layout. Topics include introduction of component layout; tutorial examples of BorderLayout, FlowLayout, BoxLayout, GridLayout, and GridBagLayout.
These sections are omitted from this Web preview version. To view the full content,
see information on how to obtain the full version this book.
Layout of Components in a Container
What Is Layout
java.awt.BorderLayout - Border Layout
java.awt.FlowLayout - Flow Layout
java.awt.BoxLayout - Box Layout
java.awt.GridLayout - Grid Layout
java.awt.GridBagLayout - Grid Bag Layout
Conclusions:
- A layout is a set of rules that defines how graphical components should be
positioned in a container.
- Java provides 5 built-in layouts: Border, Flow, Box, Grid, and Grid Bag layouts.
- java.awt.BorderLayout class allows you to manage the Border layout, which
displays 5 components in east, south, west, north, and center regions.
- java.awt.FlowLayout class allows you to manage the Flow layout, which
displays unlimited number of components in sequentially in the horizontal direction and
wraps around at the right edge of the container.
- java.awt.BoxLayout class allows you to manage the Box layout, which
displays unlimited number of components in sequentially in the horizontal or vertical direction.
Components are resized to fit the container width or height.
- java.awt.GridLayout class allows you to manage the Grid layout, which
displays components in cells of rows and columns with width and height.
Components are resized to fit cell width and height.
- java.awt.GridBagLayout class allows you to manage the Grid Bag layout, which
displays components in cells of rows and columns.
Components are not resized.
Sample programs listed in this chapter have been tested with JDK 1.3.1 to JDK 17 on Windows and macOS computers.
Table of Contents
About This Book
JDK (Java Development Kit)
Introduction of Java Swing Package
Graphics Environment of the Local System
JFrame - Main Frame Class
JLabel - Swing Label Class
JButton - Swing Button Class
JCheckBox - Swing Check Box Class
JRadioButton - Swing Radio Button Class
JTextField - Swing Text Field Class
JComboBox - Swing Combo Box Class
Menu Bar, Menus, Menu Items and Listeners
Creating Internal Frames inside the Main Frame
►Layout of Components in a Container
LookAndFeel and UIManager
Option Dialog Boxes
JEditorPane - The Editor Pane Class
SwingWorker - The Background Task Worker
AWT (Abstract Windows Toolkit)
Integration with Desktop System
Archived Tutorials
References
Full Version in PDF/EPUB