Components and their properties.

Q7. Name atleast 3 common controls. Also give some of their properties.

Ans. Components are components that defines a screen element such as text fields, labels, list boxes etc,. that are drawn on frame to get data input or to display output.

  1. JTextField: A TextField is a basic field that allows the user to type some textual information. It allows at most one line of input. The various methods and properties associated with the jTextField is given:
    Property Description
    Background Sets the background color.
    Border Sets the type of border that will surround the text field.
    Editable If set true user can edit textfield. Default it is true.
    Enabled Contains enabled state of component. True if enabled else False.
    Font Sets the font.
    Foreground Sets the foreground color.
    Horizontal Alignment Sets the horizontal alignment of text displayed in the TextField.
    Text Sets the display text.
    ToolTipText Sets the text that will appear when cursor moves over the component.
  2. JLabel: A Label is another basic control that lets you display a single line uneditable text, read-only text, an image or both text and image. The various methods and properties associated with the jLabel is given
    Property Description
    Background Sets the background color.
    Enabled Contains enabled state of component. True if enabled else False.
    Font Sets the font.
    Foreground Sets the foreground color.
    Horizontal Alignment Sets the horizontal alignment of text displayed in the TextField.
    Text Sets the display text.
  3. JRadioButton: We have used radio buttons when we wanted to provide the user several choices and allowed him to select one of the choices (the radio buttons belong to a group allowing the user to select single option). But radio buttons occupy a lot of space. Thus, in case of too many options we used Combo boxes as they help save space and are less cumbersome to design as compared to radio button.
    Property Description
    Background Sets the background color.
    ButtonGroup Specifies the name of the group of button to which the JRadioButton belongs.
    Enabled Contains enabled state of component. True if enabled else False.
    Font Sets the font.
    Foreground Sets the foreground color.
    Label Sets the display text.
    Text Sets the display text.
    Selected Sets the button as selected, if set to true, default is false.
  4. JCheckbox and JList: We used check box and list when we wanted to display multiple options like selecting favorite sports or ordering multiple food items in a restaurant. The list is a preferred option over checkbox in situations whenever multiple options are required to be selected from a large number of known set of options as they help save space and are less cumbersome to design as compared to check boxes.
    Property Description
    Background Sets the background color.
    ButtonGroup Specifies the name of the group of button to which the JRadioButton belongs.
    Font Sets the font.
    Foreground Sets the foreground color.
    Label Sets the display text.
    Text Sets the display text.
    Selected Sets the button as selected, if set to true, default is false.

Leave a Reply

Your email address will not be published. Required fields are marked *

122 Views
%d bloggers like this: