Gif create a label with text an icon with centered

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: file ImageIcon icon = new ImageIcon("image/grapes.gif"); // Create a label with text, // an icon, with centered horizontal alignment JLabel jlbl = new JLabel("Grapes", icon, SwingConstants.CENTER); // Set label's text alignment and gap between text and icon jlbl.setHorizontalTextPosition(SwingConstants.CENTER); jlbl.setVerticalTextPosition(SwingConstants.BOTTOM); jlbl.setIconTextGap(5); EE3206/EE5805 Java Programming & Applications 20 JTextField A text field is an input area where the user can type in characters. Text text fields are useful in that they enable the user to enter in variable data (such as a name or a description). javax.swing.text.JTextComponent -text: String -editable: boolean The get and set methods for these data fields are provided in the class, but omitted in the UML diagram for brevity. The text contained in this text component. Indicates whether this text component is editable (default: true). javax.swing.JTextField -columns: int -horizontalAlignment: int +JTextField() +JTextField(column: int) +JTextField(text: String) +JTextField(text: String, columns: int) The number of columns in this text field. The horizontal alignment of this text field (default: LEFT). Creates a default empty text field with number of columns set to 0. Creates an empty text field with specified number of columns. Creates a text field initialized with the specified text. Creates a text field initialized with the specified text and columns. EE3206/EE5805 Java Programming & Applications 21 JTextField Constructors & Properties JTextField(int columns) JTextField(int Creates an empty text field with the specified number of columns. JTextField(String text) JTextField(String Creates a text field initialized with the specified text. JTextField(String text, int columns) JTextField(String Creates a text field initialized with the specified text and the column size. text text horizontalAlignment horizontalAlignment editable editable columns columns EE3206/EE5805 Java Programming & Applications 22 JTextField Methods getText() getText Returns the string from the text field. setText(String text) setText(String Puts the given string in the text field. setEditable(boolean editable) setEditable(boolean Enables or disables the text field to be edited. By default, editable is true. editable setColumns(int) setColumns(int Sets the number of columns in this text field. The length of the text field is changeable. EE3206/EE5805 Java Programming & Applications 23 Example: Using Text Fields A...
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