文档

Java™ 教程-Java Tutorials 中文版
Trail: Creating a GUI with Swing
Lesson: Laying Out Components Within a Container

Laying Out Components Within a Container: Examples

The table that follows lists every example in the Laying Out Components Within a Container lesson, with links to required files and to where each example is discussed. The first column of the table has links to JNLP files that let you run the examples using Java™ Web Start.


NOTE: Release 7.0 is required to run all applets and Java Web Start examples. Most examples will run on an earlier release but you must compile and run them locally.

To run an example using Java Web Start, click the [Launch] link in the first column of the table. The first time you run an example, there will be a delay while Java Web Start downloads the JAR file containing the class files for this lesson's examples. Afterward, the examples should execute more quickly.

Compiling and Running the Examples Locally

The second column in the table below has links to zip files for each demo that you can open and run in the NetBeans IDE. Refer to Running Tutorial Examples in NetBeans IDE for more information.

If you download an individual example, take care to have all the necessary files in the proper hierarchy when you compile and run it. All of the examples in the Swing tutorial are placed in a package. For example, the components examples are placed in a components package. See the following image for the complete structure. Note that any examples using images expect their image files to be in a directory named images that is in the same directory as the example's src files.

You can find out which files each example needs by consulting the following table or by looking at the comments at the beginning of each source file.

Table of Examples

例子 Zip File
(contains all files necessary for the example plus NetBeans IDE project metadata)
Source Files
(first file has the main method)
Image and Other Files Where Described
AbsoluteLayoutDemo [Launch] Absolute Layout Demo Project AbsoluteLayoutDemo.java   Doing Without a Layout Manager
BorderLayoutDemo [Launch] Border Layout Demo Project BorderLayoutDemo.java   如何使用 BorderLayout
BoxAlignmentDemo [Launch] Box Alignment Demo Project BoxAlignmentDemo.java geek-cght.gifmiddle.gif 如何使用 BoxLayout
BoxLayoutDemo [Launch] Box Layout Demo Project BoxLayoutDemo.java   如何使用 BoxLayout
BoxLayoutDemo2 [Launch] Box Layout Demo 2 Project BoxLayoutDemo2.java, BoxLayoutDemo.java , BLDComponent.java   如何使用 BoxLayout
CardLayoutDemo [Launch] Card Layout Demo Project CardLayoutDemo.java   如何使用 CardLayout
CustomLayoutDemo [Launch] Custom Layout Demo Project CustomLayoutDemo.java   创建自定义布局管理器
FlowLayoutDemo [Launch] Flow Layout Demo Project FlowLayoutDemo.java   如何使用 FlowLayout
GridBagLayoutDemo [Launch] Grid Bag Layout Demo Project GridBagLayoutDemo.java   如何使用 GridBagLayout
GridLayoutDemo [Launch] Grid Layout Demo Project GridLayoutDemo.java   如何使用 GridLayout
SpringBox [Launch] Spring Box Project SpringBox.java
   SpringUtilities.java
  如何使用 SpringLayout
SpringCompactGrid [Launch] Spring Compact Grid Project SpringCompactGrid.java
   SpringUtilities.java
  如何使用 SpringLayout
SpringDemo1* Spring Demo 1 Project SpringDemo1.java   如何使用 SpringLayout
SpringDemo2* Spring Demo 2 Project SpringDemo2.java   如何使用 SpringLayout
SpringDemo3 [Launch] Spring Demo 3 Project SpringDemo3.java   如何使用 SpringLayout
SpringDemo4 [Launch] Spring Demo 4 Project SpringDemo4.java   如何使用 SpringLayout
SpringForm [Launch] Spring Form Project SpringForm.java
   SpringUtilities.java
  如何使用 SpringLayout
SpringGrid [Launch] Spring Grid Project SpringGrid.java
   SpringUtilities.java
  如何使用 SpringLayout
TabDemoProject [Launch] Tab Demo Project TabDemo.java   如何使用 CardLayout

*SpringDemo1 and SpringDemo2 are intentionally broken, and we don't advise running them using Java Web Start.


Previous page:
Next page: