S 2026-11-06 JTextField类是一个允许编辑单行文本的组件。 类声明以下是javax.swing.JTextField类的声明 - public class JTextField extends JTextComponent implements SwingConstants 字段以下是javax.swing.JList类的字段 - static String notifyAction - 要发送已接受字段内容的通知的操作的名称。 类构造函数 编号 构造函数 描述 1 JTextField() 构造一个新的TextField。 2 JTextField(Document doc, String text, int columns) 构造一个新的JTextField,它使用给定的文本存储模型和给定的列数。 3 JTextField(int columns) 构造具有指定列数的新空TextField。 4 JTextField(String text) 构造使用指定文本初始化的新TextField。 5 JTextField(String text, int columns) 构造一个使用指定文本和列初始化的新TextField。 类构造函数 编号 类方法 描述 1 protected void actionPropertyChanged(Action action, String propertyName) 更新文本字段的状态以响应关联操作中的属性更改。 2 void addActionListener(ActionListener l) 添加指定的操作侦听器以从此文本字段接收操作事件。 3 protected void configurePropertiesFromAction(Action a) 设置此文本字段上的属性以匹配指定Action中的属性。 4 protected PropertyChangeListener createActionPropertyChangeListener(Action a) 创建并返回一个PropertyChangeListener,它负责侦听指定Action的更改并更新相应的属性。 5 protected Document createDefaultModel() 如果没有明确给出,则创建要在构造中使用的模型的默认实现。 6 prote
阅读全文 ↗ S 2026-11-06 JComboBox类是一个组合按钮或可编辑字段和下拉列表的组件。 类声明以下是javax.swing.JComboBox类的声明 - public class JComboBox extends JComponent implements ItemSelectable, ListDataListener, ActionListener, Accessible 字段以下是javax.swing.JList类的字段 - protected String actionCommand - 此受保护字段是特定于实现的。protected ComboBoxModel dataModel - 此受保护字段是特定于实现的。protected ComboBoxEditor editor - 此受保护字段是特定于实现的。protected boolean isEditable - 此受保护字段是特定于实现的。protected JComboBox.KeySelectionManager keySelectionManager - 此受保护字段是特定于实现的。protected boolean lightWeightPopupEnabled - 此受保护字段是特定于实现的。protected int maximumRowCount - 此受保护字段是特定于实现的。protected ListCellRenderer renderer - 此受保护字段是特定于实现的。protected Object selectedItemReminder - 此受保护字段是特定于实现的。 类构造函数 编号 构造函数 描述 1 JComboBox() 使用默认数据模型创建JComboBox。 2 JComboBox(ComboBoxModel aModel) 创建一个JComboBox,从现有的ComboBoxModel获取项目。 3 JComboBox(Object[] items) 创建一个包含指定数组中元素的JComboBox。 4 JComboBox(Vector<?> items) 创建一个包含指定Vector中元素的JComboBox。 类方法以下是Swing JComboBox类中的方法列表。请参阅:https://docs.oracle.com/javase/7/docs/api/java
阅读全文 ↗ S 2026-11-06 JList类是显示对象列表并允许用户选择一个或多个项的组件。模型ListModel维护列表的内容。 类声明以下是javax.swing.JList类的声明 - public class JList extends JComponent implements Scrollable, Accessible 字段以下是javax.swing.JList类的字段 - static int HORIZONTAL_WRAP - 表示“报纸样式”布局,其中单元格水平流动然后垂直流动。static int VERTICAL - 表示单个列中单元格的垂直布局; 默认布局。static int VERTICAL_WRAP - 表示“报纸样式”布局,其中单元格垂直然后水平流动。 构造函数 编号 构造函数 描述 1 JList() 使用空的只读模型构造JList。 2 JList(ListModel dataModel) 构造一个JList,显示指定的非null模型中的元素。 3 JList(Object[] listData) 构造一个显示指定数组中元素的JList。 4 JList(Vector<?> listData) 构造一个显示指定Vector中元素的JList。 类方法下面是Swing JList类中的方法列表。 请参考官方文档 - https://docs.oracle.com/javase/7/docs/api/javax/swing/JList.html JList示例使用编辑器创建以下Java程序:JListExample.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JListExample { private JFrame mainFrame; private JLabel headerLabel; private JLabel statusLabel; private JPanel controlPanel; public JListExample(){ prepareGUI(); } public static void main(String[] args){ JListExample swingControlDemo = new JLis
阅读全文 ↗ S 2026-11-06 JRadioButton类是单选按钮的实现 - 可以选择或取消选择的项,并向用户显示其状态。 类声明以下是javax.swing.JRadioButton类的声明 - public class JRadioButton extends JToggleButton implements Accessible 类构造函数 编号 构造函数 描述 1 JRadioButton() 创建一个没有设置文本的最初未选中的单选按钮。 2 JRadioButton(Action a) 创建一个radiobutton实例,属性取自提供的Action。 3 JRadioButton(Icon icon) 使用指定的图像创建最初未选中的单选按钮,但不显示文本。 4 JRadioButton(Icon icon, boolean selected) 创建具有指定图像和选择状态但没有文本的单选按钮。 5 JRadioButton(String text, boolean selected) 创建具有指定文本和选择状态的单选按钮。 6 JRadioButton(String text, Icon icon) 创建一个具有指定文本和图像的单选按钮,此按钮最初未被选中。 7 JRadioButton(String text, Icon icon, boolean selected) 创建具有指定文本,图像和选择状态的单选按钮。 类方法 编号 方法 描述 1 AccessibleContext getAccessibleContext() 获取与此JRadioButton关联的AccessibleContext。 2 String getUIClassID() 返回呈现此组件的L&F类的名称。 3 protected String paramString() 返回此JRadioButton的字符串表示形式。 4 void updateUI() 将UI属性重置为当前外观的值。 方法继承该类继承以下类中的方法 - javax.swing.AbstractButtonjavax.swing.JToggleButtonjavax.swing.JComponentjava.awt.Containerjava.awt.Componentjava.lang.Object JRadioButton示例使用编辑器创建以
阅读全文 ↗ S 2026-11-06 JCheckBox类是复选框的实现 - 可以选择或取消选择的项,并向用户显示状态。 类声明以下是javax.swing.JCheckBox类的声明 - public class JCheckBox extends JToggleButton implements Accessible 字段以下是javax.swing.JCheckBox类的字段 - static String BORDER_PAINTED_FLAT_CHANGED_PROPERTY - 标识对flat属性的更改。 类构造函数 编号 方法 描述 1 JCheckBox() 创建一个最初未选中的复选框按钮,没有文本,也没有图标。 2 JCheckBox(Action a) 创建一个复选框,属性取自提供的Action。 3 JCheckBox(Icon icon) 使用图标创建最初未选中的复选框。 4 JCheckBox(Icon icon, boolean selected) 创建一个带有图标的复选框,并指定它是否最初被选中。 5 JCheckBox(String text) 使用文本创建最初未选中的复选框。 6 JCheckBox(String text, boolean selected) 创建一个包含文本的复选框,并指定它是否最初被选中。 7 JCheckBox(String text, Icon icon) 使用指定的文本和图标创建最初未选中的复选框。 8 JCheckBox(String text, Icon icon, boolean selected) 创建一个带有文本和图标的复选框,并指定它是否最初被选中。 类方法 编号 方法 描述 1 AccessibleContext getAccessibleContext() 获取与此JCheckBox关联的AccessibleContext。 2 String getUIClassID() 返回一个字符串,该字符串指定呈现此组件的L&F类的名称。 3 boolean isBorderPaintedFlat() 获取borderPaintedFlat属性的值。 4 protected String paramString() 返回此JCheckBox的字符串表示形式。 5 void setBorderPaintedFlat(boolean b)
阅读全文 ↗ S 2026-11-06 JColorChooser类提供了一个控件窗格,旨在允许用户操作和选择颜色。 类声明以下是javax.swing.JColorChooser类的声明 - public class JColorChooser extends JComponent implements Accessible 字段以下是javax.swing.JColorChooser类的字段 - protected AccessibleContext accessibleContextstatic String CHOOSER_PANELS_PROPERTY - chooserPanel数组属性名称。static String PREVIEW_PANEL_PROPERTY - 预览面板属性名称。static String SELECTION_MODEL_PROPERTY - 选择模型属性名称。 构造函数 编号 构造函数 描述 1 JColorChooser() 创建一个颜色选择器窗格,初始颜色为白色。 2 JColorChooser(Color initialColor) 使用指定的初始颜色创建颜色选择器窗格。 3 JColorChooser(ColorSelectionModel model) 使用指定的ColorSelectionModel创建颜色选择器窗格。 类方法 编号 类方法 描述 1 void addChooserPanel(AbstractColorChooserPanel panel) 为颜色选择器添加颜色选择器面板。 2 static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener) 创建并返回一个包含指定ColorChooser窗格的新对话框以及“确定”,“取消”和“重置”按钮。 3 AccessibleContext getAccessibleContext() 获取与此JColorChooser关联的AccessibleContext。 4 AbstractColorChooserPanel[] getChooserPanels() 返
阅读全文 ↗ S 2026-11-06 JButton类是按钮的实现。该组件具有标签,并在按下时生成事件。它也可以有一个图像。 类声明以下是javax.swing.JButton类的声明 - public class JButton extends AbstractButton implements Accessible 类构造函数 编号 构造函数 描述 1 JButton() 创建一个没有设置文本或图标的按钮。 2 JButton(Action a) 创建一个按钮,属性取自提供的Action。 3 JButton(Icon icon) 创建一个带图标的按钮。 4 JButton(String text) 创建一个包含文本的按钮。 5 JButton(String text, Icon icon) 创建一个包含初始文本和图标的按钮。 类方法 编号 方法 描述 1 AccessibleContext getAccessibleContext() 获取与此JButton关联的AccessibleContext。 2 String getUIClassID() 返回一个字符串,该字符串指定呈现此组件的L&F类的名称。 3 boolean isDefaultButton() 获取defaultButton属性的值,如果为true,则表示此按钮是JRootPane的当前默认按钮。 4 boolean isDefaultCapable() 获取defaultCapable属性的值。 5 protected String paramString() 返回此JButton的字符串表示形式。 6 void removeNotify() 覆盖JComponent.removeNotify以检查此按钮当前是否设置为RootPane上的默认按钮。如果是,请将RootPane的默认按钮设置为null,以确保RootPane不会保留无效的按钮引用。 7 void setDefaultCapable(boolean defaultCapable) 设置defaultCapable属性,该属性确定是否可以将此按钮设置为其根窗格的默认按钮。 8 void updateUI() 将UI属性重置为当前外观的值。 方法继承该类继承以下类中的方法 - javax.swing.AbstractButtonjavax.swing.JComponent
阅读全文 ↗ S 2026-11-06 JLabel类可以显示文本或图像。通过在显示区域中设置垂直和水平对齐来对齐标签的内容。默认情况下,标签在显示区域中垂直居中。默认情况下,纯文本标签前沿对齐; 默认情况下,仅图像标签水平居中。 类声明以下是javax.swing.JLabel类的声明 - public class JLabel extends JComponent implements SwingConstants, Accessible 字段以下是javax.swing.JLabel类的字段 - protected Component labelFor 类构造函数 编号 构造函数 描述 1 JLabel() 创建一个没有图像且标题为空字符串的JLabel实例。 2 JLabel(Icon image) 使用指定的图像创建JLabel实例。 3 JLabel(Icon image, int horizontalAlignment) 使用指定的图像和水平对齐创建JLabel实例。 4 JLabel(String text) 使用指定的文本创建JLabel实例。 5 JLabel(String text, Icon icon, int horizontalAlignment) 使用指定的文本,图像和水平对齐创建JLabel实例。 6 JLabel(String text, int horizontalAlignment) 使用指定的文本和水平对齐方式创建JLabel实例。 类方法 编号 类方法 描述 1 protected int checkHorizontalKey(int key, String message) 验证该键是horizontalAlignment属性的合法值。 2 protected int checkVerticalKey(int key, String message) 验证该键是verticalAlignment或verticalTextPosition属性的合法值。 3 AccessibleContext getAccessibleContext() 获取此对象的AccessibleContext。 4 Icon getDisabledIcon() 返回标签禁用时使用的图标。 5 int getDisplayedMnemonic() 返回表示助记键的键码。 6 int getD
阅读全文 ↗ S 2026-11-06 JComponent类是除顶层容器外所有Swing组件的基类。要使用继承自JComponent 一个组成部分,必须把的容纳层次结构,其根是一个顶层 Swing 容器组件。 类声明 以下是声明的 javax.swing.JComponent类: public abstract class JComponent extends Container implements Serializable 字段域 以下是java.awt.Component 类的字段: protected AccessibleContext accessibleContext -- AccessibleContext 可以带此JComponent。 protected EventListenerList listenerList -- 此组件的事件侦听器的列表。 static String TOOL_TIP_TEXT_KEY -- 注释显示当光标在组件上,也被称为 "value tip", "flyover help", 或 "flyover label". protected ComponentUI ui -- 此组件代表的外观和风格。 static int UNDEFINED_CONDITION -- Constant used by some of the APIs to mean that no condition is defined. static int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT -- 常数用于registerKeyboardAction,意味着当接收组件是一个聚焦组件的基类,或者本身就是焦点的组件,该命令要调用。 static int WHEN_FOCUSED -- 常数用于registerKeyboardAction,意味着命令组件具有焦点时要调用。 static int WHEN_IN_FOCUSED_WINDOW -- 常数用于registerKeyboardAction,意味着当接收组件具有焦点的窗口,或者是本身的重点组成部分,该命令调用。 类构造函数 S.N. 构造函数 & 描述 1 JComponent() Default JComponent constructor. 类方法 S.N. 方法 & 描述 1 void addAn
阅读全文 ↗ S 2026-11-06 类容器是AWT容器的超类。容器对象可以包含其他AWT组件。 类声明 以下是声明 java.awt.Container 类: public class Container extends Component 类构造函数 S.N. 构造函数 & 描述 1 Container() This creates a new Container. 类方法 S.N. 方法 & 描述 1 Component add(Component comp) Appends the specified component to the end of this container. 2 Component add(Component comp, int index) Adds the specified component to this container at the given position. 3 void add(Component comp, Object constraints) Adds the specified component to the end of this container. 4 void add(Component comp, Object constraints, int index) Adds the specified component to this container with the specified constraints at the specified index. 5 Component add(String name, Component comp) Adds the specified component to this container. 6 void addContainerListener(ContainerListener l) Adds the specified container listener to receive container events from this container. 7 protected void addImpl(Component comp, Object constraints, int index) Adds the specified component to this cont
阅读全文 ↗ S 2026-11-06 Component类是AWT的非菜单用户界面控件的抽象基类。Component表示具有图形表示的对象。 类声明以下是java.awt.Component类的声明 - public abstract class Component extends Object implements ImageObserver, MenuContainer, Serializable 字段以下是java.awt.Component类的字段 - static float BOTTOM_ALIGNMENT - getAlignmentY()使用的常量。static float CENTER_ALIGNMENT - getAlignmentY()和getAlignmentX()使用的常量。static float LEFT_ALIGNMENT - getAlignmentX()使用的常量。static float RIGHT_ALIGNMENT - getAlignmentX()使用的常量。static float TOP_ALIGNMENT - getAlignmentY()使用的常量。 类构造函数 protected Component() - 它用于创建一个新的组件。 类方法以下是Swing Component类中的方法列表。 boolean action(Event evt, Object what) - Deprecated. As of JDK version 1.1, should register this component as ActionListener on the component which fires action events.void add(PopupMenu popup) - Adds the specified popup menu to the component.void addComponentListener(ComponentListener l) - Adds the specified component listener to receive the component events from this component.void addFocusListener(FocusListener l) - Adds the speci
阅读全文 ↗ S 2026-11-06 每个用户界面都考虑以下三个主要方面 - UI元素 - 这些是用户最终看到并与之交互的核心可视元素。GWT提供了从基本到复杂的广泛使用和常见元素的大量列表,我们将在本教程中介绍。布局 - 它们定义了如何在屏幕上组织UI元素,并为GUI(图形用户界面)提供最终外观。这部分将在布局章节中介绍。行为 - 这些是用户与UI元素交互时发生的事件。这部分将在“事件处理”一章中介绍。 每个SWING控件都从以下Component类层次结构继承属性。 编号 类 描述 1 Component类 Component是SWING的非菜单用户界面控件的抽象基类,Component表示具有图形表示的对象。 2 Container类 Container是可以包含其他SWING组件的组件。 3 JComponent类 JComponent是所有SWING UI组件的基类。要使用从JComponent继承的SWING组件,组件必须位于包含层次结构中,其根是顶级SWING容器。 SWING UI元素以下是使用SWING设计GUI时常用控件的列表。 编号 类 描述 1 JLabel类 JLabel对象是用于在容器中放置文本的组件。 2 JButton类 该类创建一个带标签的按钮。 3 JColorChooser类 JColorChooser类提供了一个控件窗格,允许用户操作和选择颜色。 4 JCheckBox类 JCheckBox是一个图形组件,可以处于on(true)或off(false)状态。 5 JRadioButton类 JRadioButton类是一个图形组件,可以处于on(true)或off(false)状态。在一组。 6 JList类 JList组件向用户呈现文本项的滚动列表。 7 JComboBox类 JComboBox组件向用户显示一个显示选项菜单。 8 JTextField类 JTextField对象是一个文本组件,用于编辑单行文本。 9 JPasswordField类 JPasswordField对象是专门用于输入密码的文本组件。 10 JTextArea类 JTextArea对象是一个文本组件,用于编辑多行文本。 11 ImageIcon类 ImageIcon控件是Icon接口的一个实现,它从图像绘制图标。 12 JScrollbar类 Scrollbar控件表示滚动条组件,以便
阅读全文 ↗