Java Reference
In-Depth Information
Figure 2.4 A frame generated by
SimplePanelFrameDriver
with a border layout. Note
that the panel at 'West' has been constructed with width 50 and height 20. While the width
is obeyed, the height has changed to fill the available space
specified by the constants
CENTER
,
NORTH
,
SOUTH
,
EAST
and
WEST
. These constants
are defined in class
BorderLayout
; see Figure 2.5a). If a border component is not
present, then the central component extends in that direction. The central com-
ponent usually contains the main information. The border components contain
additional information such as a status bar in the 'South'-component. To insert a
component
childComp
into the content pane at location
pos
we use method
this
.getContentPane().add(childComp,pos)
where
pos
is one of the constants
BorderLayout.CENTER
,
BorderLayout.NORTH
,
BorderLayout.SOUTH
,
BorderLayout.EAST
or
BorderLayout.WEST
.
The code for class
SimplePanelFrame
and the listing for the driver class
SimplePanelFrameDriver
follow. The first class is derived from
SimpleFrame
.
The five panels are created in its constructor and then embedded into the content
pane. The driver class generates a
SimplePanelFrame
and makes it visible. The
result is shown in Figure 2.4. There one can see that all the border panels are sized
to span the entire width or height of the content pane. The other dimensions are
the default width and height, which are 10 on most platforms. The white panel
CPWest
at 'West' has width 50 as specified in its constructor. The height specifi-
cation of 20 is ignored in the layout; the height of panel
CPWest
is extended to fill
the available height inside the frame. The central component is also extended to
fill all the space in the middle.
File:
its/SimpleFrameWithPanels/SimplePanelFrame.java
package
its.SimpleFrameWithPanels;
1.
2.
3.
import
java.awt.*;
import
javax.swing.JFrame;
4.
import
its.SimpleFrame.SimpleFrame;
5.
6.
Search WWH ::
Custom Search