复选框 CHeckbox 个开关按钮( toggle button)有两种状态,就像是一个电灯开 关。 TOggle Button类继承 Abstract Button并实现一个开关按钮。用 户通常使用其子类 J CheckBox和 JRadio Button进行开或关两种状态 的选择。 J Checkbox继承了 Abstract Button类的所有属性,并提供了创建复 选框的几种构造方法 javax. swing. AbstractButton javax.swing. JToggleButton javax.swing. JCheck Box JCheckBoxo Creates a default check box button with no text and icon JCheckBox(text: String) Creates a check box with text JCheckBox(text: String, selected Creates a check box with text and specifies whether the check box is initially selected CHeckbOx(icon: Icon) Creates a checkbox with an icon JCheckBox( text: String, icon: Icon) Creates a checkbox with text and an icon JCheckBox( text: String, icon: Icon. Creates a check box with text and an icon, and specifies whether the check selected boolean) box is initially selected
复选框JCheckBox 一个开关按钮(toggle button)有两种状态,就像是一个电灯开 关。JToggleButton类继承AbstractButton并实现一个开关按钮。用 户通常使用其子类JCheckBox和JRadioButton进行开或关两种状态 的选择。 JCheckBox继承了AbstractButton类的所有属性,并提供了创建复 选框的几种构造方法。 javax.swing.JCheckBox +JCheckBox() +JCheckBox(text: String) +JCheckBox(text: String, selected: boolean) +JCheckBox(icon: Icon) +JCheckBox(text: String, icon: Icon) +JCheckBox(text: String, icon: Icon, selected: boolean) Creates a default check box button with no text and icon. Creates a check box with text. Creates a check box with text and specifies whether the check box is initially selected. Creates a checkbox with an icon. Creates a checkbox with text and an icon. Creates a check box with text and an icon, and specifies whether the check box is initially selected. javax.swing.AbstractButton javax.swing.JToggleButton
Example7.32:使用复选框 在上例中,添加三个复 CheckBoxDemo v Centered 选框,命名为 Centered Wecome to java v Bold Bod和 iTalic,用户使用 v Italic Left 它们可以指定信息是否 Right 居中、粗体、斜体 ButtonDemo Chec kBoxDemo Check BoxDemo
Example 7.3.2: 使用复选框 在上例中,添加三个复 选框,命名为Centered、 Bold和Italic,用户使用 它们可以指定信息是否 居中、粗体、斜体 CheckBoxDemo ButtonDemo CheckBoxDemo