Programming in Java
CBCS BHCS03
By Parul Chachra
Chapter 31
Introducing Swing
Reference: Schildt, H. Java: The Complete Reference. 7th ediEon. McGraw-
Hill EducaEon
Components
• In general, Swing components are derived from the JComponent class
• JComponent provides the funcEonality that is common to all components
• For example, JComponent supports the pluggable look and feel
• JComponent inherits the AWT classes Container and Component
• Thus, a Swing component is built on and
compaEble with an AWT component
Components
• All of Swing’s components are represented by
classes defined within the package javax.swing:
Containers
• Swing defines two types of containers
– Lightweight Containers – Top-level containers
Lightweight Containers
• Lightweight containers do inherit JComponent
• An example of a lightweight container is JPanel, which is a general-purpose container
• Lightweight containers are oTen used to organize and manage groups of related components because a lightweight container can be contained within
another container
• Thus, you can use lightweight containers such as JPanel to create subgroups of related controls that are contained within an outer container