Panels and Layouts
The actual appearance of the AWT components on the screen is usually determined by two factors; how those components are added to the panel and the layout manager that panel is currently using to layout the screen. Each Panel on the screen can have it's own layout manager. The AWT provides 5 basic layout managers :
FlowLayout Class
The flowlayout class is the most basic of the layouts, using this method componets are added to the panel one at a time, row by row. If a component doesn't fit then it is wrapped to the next row. The alignment of the componets can be altered. It's default value is centered and it can be either left or right justified. This is done using the lines :
setLayout(new FlowLayout.LEFT));
setLayout(new FlowLayout.RIGHT));
setLayout(new FlowLayout.LEFT,30,10));
setLayout(new FlowLayout.RIGHT,50,20));
|
import java.awt.*; public class GridLayoutTest extends java.applet.Applet { public void init() { setLayout (new GridLayout(3,3,20,10)); add(new Button("One")); add(new Button("Two")); add(new Button("Three")); add(new Button("Four")); add(new Button("Five")); } } |
|