Java Reference
In-Depth Information
7. public class SimplePanelFrame extends SimpleFrame
8. {
9.
public SimplePanelFrame()
10.
{
11.
ColorPanel CPWest = new ColorPanel(Color.white,50,20);
12.
ColorPanel CPEast = new ColorPanel(Color.red);
13.
ColorPanel CPNorth = new ColorPanel(Color.yellow);
14.
ColorPanel CPSouth = new ColorPanel(Color.green);
15.
ColorPanel CPCenter = new ColorPanel(Color.blue);
16.
this .getContentPane().add(CPWest,BorderLayout.WEST);
17.
this .getContentPane().add(CPEast,BorderLayout.EAST);
18.
this .getContentPane().add(CPNorth,BorderLayout.NORTH);
19.
this .getContentPane().add(CPSouth,BorderLayout.SOUTH);
20.
this .getContentPane().add(CPCenter,BorderLayout.CENTER);
21.
}
22. }
File: its/SimpleFrameWithPanels/SimplePanelFrameDriver.java
1. package its.SimpleFrameWithPanels;
2.
3. public class SimplePanelFrameDriver
4. {
5.
public static void main(String[] args)
6.
{
7.
SimplePanelFrame spFrame = new SimplePanelFrame();
8.
spFrame.showIt("Simple Panel Frame");
9.
}
10. }
We now introduce two more layout managers: flow layout manager ( FlowLayout )
and grid layout manager ( GridLayout ). Both classes as well as BorderLayout
implement the interface LayoutManager . Layouts are not restricted to frames.
Every Swing component into which other components can be embedded (a so-
called container ) has a layout. The default layout is a border layout. In order to
change the layout of a parent component parentComp to another layout newLayout
one uses the command
parentComp.setLayout(newLayout)
If a component has a flow layout then the embedded components are placed
row-wise from left to right. If a row is full, the next one is started. Row layout
(mostly) respects the dimensions of the embedded components. The order
of the calls parentComp.add(child) determines the order of the embedded
components in the parent component. The height of a row is determined at
Search WWH ::




Custom Search