Java's BorderLayout

Source: Internet
Author: User

The layout manager has the concept of four sides and an intermediate area. When we add something to the panel using BorderLayout, we must use the Add () method to take a string object as its first argument, and the string must be specified (correct capitalization) "North" (Upper), "South" (Next), "West" (left), " East "(right) or" Center ". If we misspell or not capitalize, we get a compile-time error, and the program doesn't run as you would expect. Fortunately, we will soon find more improvements in Java 1.1.
This is a simple example of a program:

: Borderlayout1.java
//demonstrating the BorderLayout
import java.awt.*;
Import java.applet.*;

public class BorderLayout1 extends applets {public
  void init () {
    int i = 0;
    SetLayout (New BorderLayout ());
    Add ("North", New button ("button" + i++));
    Add ("South", New button ("button" + i++));
    Add ("East", New button ("button" + i++));
    Add ("West", New button ("button" + i++));
    Add ("Center", New button ("button" + i++));
  }
///:~

In addition to every position in center, when the element expands to its maximum in other spaces, we compress it to the smallest size suitable for the space. However, "center" expands to occupy only the central position.
BorderLayout is the default layout manager for Applications and dialog boxes.

Related Article

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.