# 课程：在容器中布置组件

> 原文： [https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html](https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html)

[Examples Index](../examples/layout/index.html)

本课程将介绍如何使用 Java 平台提供的布局管理器。它还告诉您如何使用绝对定位（没有布局管理器）并给出编写自定义布局管理器的示例。对于每个布局管理器（或缺少布局管理器），本课程指向可以使用 Java™Web Start 运行的示例。通过调整示例窗口的大小，您可以看到大小更改如何影响布局。

* * *

**Note:** This lesson covers writing layout code by hand, which can be challenging. If you are not interested in learning all the details of layout management, you might prefer to use the `GroupLayout` layout manager combined with a builder tool to lay out your GUI. One such builder tool is the [NetBeans IDE](../learn/index.html). Otherwise, if you want to code by hand and do not want to use `GroupLayout`, then `GridBagLayout` is recommended as the next most flexible and powerful layout manager.

* * *

如果您对使用 JavaFX 创建 GUI 感兴趣，请参阅[在 JavaFX](https://docs.oracle.com/javase/8/javafx/layout-tutorial/index.html) 中使用布局。

## [布局管理员视觉指南](visual.html)

This section shows examples of the standard layout managers and points to the how-to section for each one.

## [使用布局管理器](using.html)

This section gives general rules on using the standard layout managers. It includes how to set the layout manager, add components to a container, provide size and alignment hints, put space between components, and set the orientation of the container's layout so that it is appropriate for the locale in which the program is running. It also has some tips for choosing the right layout manager.

## [布局管理的工作原理](howLayoutWorks.html)

This section goes through a typical layout sequence and then describes what happens when a component's size changes.

## [如何使用...](layoutlist.html)

This series of sections tells you how to use each of the general-purpose layout managers that the Java platform provides.

## [创建自定义布局管理器](custom.html)

Instead of using one of the Java platform's layout managers, you can write your own.

布局管理器必须实现`LayoutManager`接口，该接口指定每个布局管理器必须定义的五种方法。可选地，布局管理器可以实现`LayoutManager2`，它是`LayoutManager`的子接口。

## [没有布局管理器（绝对定位）](none.html)

如有必要，您可以在不使用布局管理器的情况下定位组件。通常，此解决方案用于指定组件的绝对大小和位置。

## [解决常见布局问题](problems.html)

一些最常见的布局问题涉及显示太小的组件 - 或根本不显示。本节介绍如何解决这些和其他常见布局问题。

## [问题和练习](../QandE/questions-ch4.html)

尝试这些问题和练习来测试您在本课中学到的内容。

如果您对使用 JavaFX 创建 GUI 感兴趣，请参阅[在 JavaFX](https://docs.oracle.com/javase/8/javafx/layout-tutorial/index.html) 中使用布局。