Key Swing Containers
o
JFrame
o
Is a window with a title bar, menu bar, and border(inset)
o
Can be iconified
o
Is free-floating
Ie cannot be nested inside another container
o
Consists of several layers
Has a JRootPane
Each JRootPane has a jLayeredPane, JMenuBar, JContentPane, and JGlassPane
o
Add components to the content pane
o
JPanel
o
Is A generic container, always inside some other container
Cannot float freely on the screen
o
Used to group controls together
You can nest several JPanels inside another JPanel
o
Can also e used as an area to draw on
o
You must extend the class, and override pointComponent()
Layout Manager
o
Are classes that determine where components are placed inside a container
o
Do not determine exact placement, but implement a general layout policy
o
If you resize the container, the components may be repositioned or change in size
o
Use setLayout() to set a container’s layout manager
o
Eg: myContainer.setLayout(new FlowLayout());
o
Set the layout first, then add components
o
With some layouts, the order in which you add is important
This
preview
has intentionally blurred sections.
Sign up to view the full version.
o
FlowLayout
o

This is the end of the preview.
Sign up
to
access the rest of the document.
- Fall '09
- Li
- container, new JButton, Layout manager, size
-
Click to edit the document details