什么是BorderLayout : 边界布局 « Swing « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » Swing » 边界布局 
14. 86. 1. 什么是BorderLayout

BorderLayout is the default layout manager for the content pane of a JFrame, JWindow, JDialog, JInternalFrame, and JApplet.

  1. Place components against any of the four borders of the container and in the center.
  2. The component in the center fills the available space.
  3. You do not need specify all five areas of the container.
  4. The component in the north region takes up the entire width of the container along its top.
  5. South does the same along the bottom.
  6. The heights of north and south will be the preferred heights of the added component.
  7. The east and west areas are given the widths of the component each contains, where the height is whatever is left in the container after satisfying north's and south's height requirements.
  8. Any remaining space is given to the component in the center region.
  9. Constants used to specify areas: CENTER, EAST, NORTH, SOUTH, WEST

Its constructors:

public BorderLayout()
public BorderLayout(int hgap, int vgap)
什么是BorderLayout
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;

public class BorderLayoutExample extends JFrame {

  public static void main(String[] args) {
    BorderSample bs = new BorderSample();
    bs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = bs.getContentPane();
    pane.setLayout(new BorderLayout());
    JLabel label = new JLabel("North", JLabel.CENTER);
    label.setFont(new Font("Courier", Font.BOLD, 36));
    label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    pane.add(label, BorderLayout.NORTH);
    label = new JLabel("South", JLabel.CENTER);
    label.setFont(new Font("Courier", Font.BOLD, 36));
    label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    pane.add(label, BorderLayout.SOUTH);
    label = new JLabel("East", JLabel.CENTER);
    label.setFont(new Font("Courier", Font.BOLD, 36));
    label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    pane.add(label, BorderLayout.EAST);
    label = new JLabel("West", JLabel.CENTER);
    label.setFont(new Font("Courier", Font.BOLD, 36));
    label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    pane.add(label, BorderLayout.WEST);
    label = new JLabel("Center", JLabel.CENTER);
    label.setFont(new Font("Courier", Font.BOLD, 36));
    label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    pane.add(label, BorderLayout.CENTER);
    bs.setSize(400300);
    bs.setVisible(true);
  }

}
14. 86. 边界布局
14. 86. 1. 什么是BorderLayout什么是BorderLayout
14. 86. 2. A BorderLayout divides the space into five regions: North, West, South, East and Centre.
14. 86. 3. 使用BorderLayout使用BorderLayout
14. 86. 4. 典型的使用边界布局管理器。典型的使用边界布局管理器。
14. 86. 5. Place multiple components into one of the regions of a BorderLayout-managed containerPlace multiple components into one of the regions of a BorderLayout-managed container
14. 86. 6. 结合BorderLayout和GridLayout结合BorderLayout和GridLayout
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.