Layout Manager is used to manage the layout of components in a container in a graphical user interface, such as sort order, component size, position
The layout manager mainly includes: Flowlayout,borderlayout,gridlayout,cardlayout,gridbaglayout
You should be aware of these two points when arranging the size of components in a program
1. The layout manager in the container is responsible for the size and location of each component, so users cannot set these properties for the component in this case. If you try to use setlocation (), SetSize (), Setbound (), and so forth in the Java language, it will be overwritten by the layout manager.
2. If you need to set the size and location of the component yourself, you need to call the setlayout (null) method to cancel the container's layout manager.
Example Set Layout Manager applet
ImportJava.awt.Button;Importjava.awt.FlowLayout;ImportJava.awt.Frame; Public classEp2_1 {PrivateFrame F; PrivateButton B1; PrivateButton B2; Public Static voidMain (string[] args) {ep2_1 that=Newep2_1 (); That.go (); } Public voidGo () {f=NewFrame ("title"); F.setlayout (NewFlowLayout ());//set layout manager to FlowLayoutb1=NewButton ("1"); B2=NewButton ("2"); F.add (B1); F.add (B2); F.pack ();//Compact arrangement allows the window to be as small as possible, just to accommodate two buttonsF.setvisible (true); }}
Java Interface Layout Manager