Java Swing
Java Swing
AWT
Abstract Window Toolkit
set has quite a few bugs and does take up a lot of system resources when
compared to equivalent Swing resources.
Layout Managers
● Control the arrangement of components within containers:
○ BorderLayout: Arranges components in north, south, east, west, and center
regions
○ FlowLayout: Arranges components in a directional flow
○ GridLayout: Arranges components in a grid
○ BoxLayout: Arranges components either vertically or horizontally
○ CardLayout: Shows only one component at a time
○ GridBagLayout: Most flexible but complex layout manager
Label JLabel Displays static text or an icon. Not editable by the user.
Text Field JTextField Single-line input for text. Used to get user input.
Text Area JTextArea Multi-line text input area. Supports scrolling with JScrollPane.
Password Field JPasswordField Text field that hides input (e.g., for passwords).
Radio Button JRadioButton Select one option among many (grouped using ButtonGroup).
List JList Displays a list of items; can allow single or multiple selections.
Slider JSlider Allows the user to choose a value from a range using a sliding knob.
Spinner JSpinner Lets the user increment/decrement a value (numeric, date, or list-based).
Progress Bar JProgressBar Shows progress of a task as a bar filled from 0% to 100%.
Toggle Button JToggleButton Button that maintains its on/off state when clicked.
Tree JTree Displays hierarchical data in a tree format (like file systems).
Event Handling Architecture
Swing follows a delegation event model:
Conclusion
Java Swing provides a powerful and flexible toolkit for building desktop applications. By
understanding its class hierarchy, utilizing various containers and layout managers, and
implementing event handling, developers can create responsive and well-structured UIs.