Programming in Java
CBCS BHCS03
By Parul Chachra
Chapter 31
Introducing Swing
Reference: Schildt, H. Java: The Complete Reference. 7th ediEon. McGraw-
Hill EducaEon
Top – Level Containers
• The first are top-level containers:
– JFrame – JApplet – JWindow – JDialog.
• These containers do not inherit JComponent
• They do, however, inherit the AWT classes Component and Container
• Most commonly used top-level container for applicaEons is JFrame
• The one used for applets is JApplet.
Top – Level Containers
• Features of Top-level containers
• The top-level containers are heavyweight which makes these containers a special case in the Swing component library
• A top-level container must be at the top of a containment hierarchy
• A top-level container is not contained within any other container
• Furthermore, every containment hierarchy must begin with a top-level container
Top – Level Containers
• Each top-level container defines a set of panes
• At the top of the hierarchy is an instance of JRootPane.
• JRootPane is a lightweight container whose purpose is to manage the other panes
• The panes that comprise the root pane are called the glass pane, the content pane, and the layered pane
• The glass pane is the top-level pane. By default, it is a transparent instance of JPanel.
• The glass pane enables you to manage mouse events that affect the enEre container (rather than an individual control) or to paint over any other component, for example