Java Interface Layout Manager

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.