The FlowLayout Class in AWT
The FlowLayout class is perhaps the simplest of all of the java.awt layout classes. It simply lays out components from left to right, in the order in which they were added to the applet. This is the default layout manager, so it is used automatically even if you do not specify one directly.
However, if you want to specify use of the FlowLayout class (or any other layout manager) directly, you would usually call the setLayout method within your container’s init method, such as the following:
setLayout(new FlowLayout());
add(new Button("Layout"));
add(new Button("Managers"));
add(new Button("Rule!"));
You can send parameters to the FlowLayout constructor to specify both the layout’s alignment as well as the horizontal and vertical gaps between components.
Other than the default constructor, there are two other FlowLayout constructor methods. The first takes an int value describing the alignment of the layout. There are five values that can be sent as the parameter: LEFT, CENTER, RIGHT, LEADING, and TRAILING. The following demonstrates how to create a left-justified FlowLayout with horizontal and vertical gap size of 10:
setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
If no parameters are sent to the constructor, the default alignment is FlowLayout.CENTER and the default gap size is set to five pixels.


LinkBack URL
About LinkBacks
Reply With Quote

LinkBacks Enabled by vBSEO
Bookmarks