You can set the horizontal text position using one of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Horizontal relative to the icon. You can set the horizontal text position using one of the five constants: You LEADING, LEFT, CENTER, RIGHT, TRAILING. The default horizontal text position is SwingConstants.RIGHT. The EE3206/EE5805 Java Programming & Applications 11 Vertical Text Positions Vertical text position specifies the vertical position of the text relative Vertical to the icon. You can set the vertical text position using one of the three constants: You TOP, CENTER. The default vertical text position is SwingConstants.CENTER. The EE3206/EE5805 Java Programming & Applications 12 Example: Using Buttons Write a program that displays a message on a panel and uses two buttons, <= and =>, to move the message on the panel to the left or right. ButtonDemo Run MessagePanel JButton JButton EE3206/EE5805 Java Programming & Applications 13 JCheckBox JCheckBox inherits all the properties such as text, icon, mnemonic, verticalAlignment, horizontalAlignment, horizontalTextPosition, verticalTextPosition, and selected from AbstractButton, and provides several constructors to create check boxes. javax.swing.AbstractButton javax.swing.JToggleButton 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. 14 EE3206/EE5805 Java Programming & Applications Example: Using Check Boxes Add three check boxes named Centered, Bold, and Italic into the Centered Bold Italic previous example to let the user specify whether the message is centered, bold, or italic. ButtonDemo CheckBoxDemo Run CheckBoxDemo EE3206/EE5805 Java Programming & Applications 15 JRadioButton Radio buttons are variations of check boxes. They are often used in the group, where only one button is checked at a time. They can be grouped with the following code: ButtonGroup btg = new ButtonGroup(); btg.add(jrb1); btg.add(jrb2); javax.swing.AbstractButton j avax.swing.JToggleButton j avax.swing.JRadioButton + JRadioButton() +JRadioButton(text: String) +JRadioButton(text: String, selected: boolean) +JRadioButton(icon: Icon) +JRadioButton(text: String, icon: Icon) +JRadioButton(text: String, icon: Icon, selected: boolean) C reates a def...
View Full Document

This note was uploaded on 01/11/2011 for the course EE 3206 taught by Professor Cwting during the Spring '07 term at City University of Hong Kong.

Ask a homework question - tutors are online