Documentation

The Java™ Tutorials
Hide TOC
Using Swing Components使用Swing组件
Trail: Creating a GUI With Swing使用Swing创建GUI

Lesson: Using Swing Components课:使用Swing组件

Examples Index示例索引

This lesson gives you the background information you need to use the Swing components, and then describes every Swing component. 本课程为您提供了使用Swing组件所需的背景信息,然后介绍了每个Swing组件。It assumes that you have successfully compiled and run a program that uses Swing components, and that you are familiar with basic Swing concepts. 它假设您已经成功编译并运行了一个使用Swing组件的程序,并且您熟悉基本的Swing概念。These prerequisites are covered in Getting Started with Swing and Learning Swing with the NetBeans IDE.这些先决条件将在使用Swing入门使用NetBeans IDE学习Swing中介绍。

Using Top-Level Containers使用顶级容器

Discusses how to use the features shared by the JFrame, JDialog, and JApplet classes — content panes, menu bars, and root panes. 讨论如何使用JFrameJDialogJApplet类共享的功能;内容窗格、菜单栏和根窗格。It also discusses the containment hierarchy, which refers to the tree of components contained by a top-level container.它还讨论了包含层次结构,它指的是顶级容器包含的组件树。

The JComponent ClassJComponent

Tells you about the features JComponent provides to its subclasses — which include almost all Swing components — and gives tips on how to take advantage of these features. 告诉您JComponent为其子类提供的功能—其包括几乎所有的摆动部件;并给出了如何利用这些功能的提示。This section ends with API tables describing the commonly used API defined by JComponent and its superclasses, Container and Component.本节以描述JComponent及其超类:ContainerComponent定义的常用API的API表结束。

Using Text Components使用文本组件

Describes the features and API shared by all components that descend from JTextComponent. 描述从JTextComponent派生的所有组件共享的功能和API。You probably do not need to read this section if you are just using text fields (formatted or not) or text areas.如果您只是使用文本字段(格式化或不格式化)或文本区域,则可能不需要阅读本节。

How to...

Sections on how to use each Swing component, in alphabetical order. We do not expect you to read these sections in order. 关于如何使用每个Swing组件的章节,按字母顺序排列。我们不希望您按顺序阅读这些章节。Instead, we recommend reading the relevant "How to" sections once you are ready to start using Swing components in your own programs. 相反,一旦您准备好在自己的程序中开始使用Swing组件,我们建议您阅读相关的“如何”部分。For example, if your program needs a frame, a label, a button, and a color chooser, you should read How to Make Frames, How to Use Labels, How to Use Buttons, and How to Use Color Choosers.例如,如果您的程序需要框架、标签、按钮和颜色选择器,则应阅读如何制作框架如何使用标签如何使用按钮以及如何使用颜色选择器

Using HTML in Swing Components在Swing组件中使用HTML

Describes how to vary the font, color, or other formatting of text displayed by Swing components by using HTML tags.描述如何使用HTML标记更改Swing组件显示的文本的字体、颜色或其他格式。

Using Models使用模型

Tells you about the Swing model architecture. 介绍Swing模型体系结构。This variation on Model-View-Controller (MVC) means that you can, if you wish, specify how the data and state of a Swing component are stored and retrieved. 模型视图控制器(MVC)的这种变化意味着,如果您愿意,可以指定如何存储和检索Swing组件的数据和状态。The benefits are the ability to share data and state between components, and to greatly improve the performance of components such as tables that display large amounts of data.其好处是能够在组件之间共享数据和状态,并大大提高组件(如显示大量数据的表)的性能。

Using Borders使用边框

Borders are very handy for drawing lines, titles, and empty space around the edges of components. 边框对于在组件边缘周围绘制线条、标题和空白非常方便。(You might have noticed that the examples in this trail use a lot of borders.) (您可能已经注意到,本文中的示例使用了大量边框。)This section tells you how to add a border to any JComponent.本节告诉您如何向任何JComponent添加边框。

Using Icons使用图标

Many Swing components can display icons. 许多Swing组件可以显示图标。Usually, icons are implemented as instances of the ImageIcon class.通常,图标被实现为ImageIcon类的实例。

Solving Common Component Problems解决常见组件问题

This section discusses solutions to common component-related problems.本节讨论常见组件相关问题的解决方案。

If you are interested in using JavaFX to create your GUI, see Using JavaFX Charts and Using JavaFX UI Controls.如果您对使用JavaFX创建GUI感兴趣,请参阅使用JavaFX图表使用JavaFXUI控件


Previous page: Previous Lesson
Next page: Using Top-Level Containers