The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
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中介绍。
Discusses how to use the features shared by the 讨论如何使用JFrame
, JDialog
, and JApplet
classes content panes, menu bars, and root panes. JFrame
、JDialog
和JApplet
类共享的功能;内容窗格、菜单栏和根窗格。It also discusses the containment hierarchy, which refers to the tree of components contained by a top-level container.它还讨论了包含层次结构,它指的是顶级容器包含的组件树。
JComponent
类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
及其超类:Container
和Component
定义的常用API的API表结束。
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.如果您只是使用文本字段(格式化或不格式化)或文本区域,则可能不需要阅读本节。
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.例如,如果您的程序需要框架、标签、按钮和颜色选择器,则应阅读如何制作框架、如何使用标签、如何使用按钮以及如何使用颜色选择器。
Describes how to vary the font, color, or other formatting of text displayed by Swing components by using HTML tags.描述如何使用HTML标记更改Swing组件显示的文本的字体、颜色或其他格式。
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.其好处是能够在组件之间共享数据和状态,并大大提高组件(如显示大量数据的表)的性能。
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
添加边框。
Many Swing components can display icons. 许多Swing组件可以显示图标。Usually, icons are implemented as instances of the 通常,图标被实现为ImageIcon
class.ImageIcon
类的实例。
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控件。