Package com.ms.ui |
![]() Previous |
![]() Contents |
![]() Index |
![]() Next |
public class UIChoice extends UIPanel { // Constructors public UIChoice(); // Methods public Component add(Component comp); public Component addString(String s); public UIMenuList getMenu(); public int getRoleCode(); public Component getSelectedComp(); public void setSelectedComp(Component comp); public void layout(); public Dimension minimumSize(); public Dimension preferredSize(); public void initGraphics(); public boolean action(Event e, Object obj); }
A class that implements a choice control, or combo box. A UIChoice object manages the following components.
Component | Description |
UIMenuList component | Displays the pop-up list of items that can be selected by the choice control. |
UIMenuButton component | Launches or cancels the associated pop-up list. |
UIItem component | Displays the choice control's currently selected item. |
When a UIChoice object is first created, its associated UIMenuList object is empty. To add items to the list, call the add or addString method, as follows.
// Construct a UIChoice object. UIChoice c = new UIChoice(); // Create an array of Strings and add each element // in the array to the choice control. String s[] = {"Item 1", "Item 2", "Item 3", "Item 4"}; for (int i=0; i<4; i++) c.addString(s[i]); // Initialize the choice control to display the // first element in the array. c.setSelectedComp(new UIText(s[0])); // Add the choice control to the container. add(c);
public UIChoice();Creates an empty choice control.
Remarks:
Call add or addString to add items to the control's pop-up list.
public boolean action(Event e, Object obj);Updates the choice control to display the currently selected item.
Return Value:
Returns false.
Parameter Description e The event posted to the control. obj The object that posted the event.
public Component add(Component comp);Adds the specified component to the end of the choice control's associated pop-up list.
Return Value:
Returns the component that was added.
Parameter Description comp The component to be added to the choice control.
public Component addString(String s);Adds the specified text to the end of the choice control's associated pop-up list.
Return Value:
Returns the text component that was added.
Parameter Description s The text to be added to the choice control.
public UIMenuList getMenu();Retrieves the choice control's associated pop-up list.
Return Value:
Returns the associated UIMenuList object.
public int getRoleCode();Retrieves the role of the choice control.
Return Value:
Returns the ROLE_SYSTEM code that best describes the role of the control.
Remarks:
This method returns the ROLE_SYSTEM_COMBOBOX code.
public Component getSelectedComp();Retrieves the choice control's currently selected item.
Return Value:
Returns the control's selected component.
public void initGraphics();Called to perform initialization when the graphics context is first available.
Return Value:
No return value.
Remarks:
This method adds the UIMenuButton component to the choice control. By default, the button displays the system-defined down arrow.
public void layout();Lays out the choice control.
Return Value:
No return value.
public Dimension minimumSize();Determines the minimum size of the choice control.
Return Value:
Returns a Dimension object containing the minimum dimensions (in pixels).
Remarks:
The minimum size is based on the associated button's minimum size plus the choice control's insets; an additional 100 pixels are added to the control's width.
public Dimension preferredSize();Determines the preferred size of the choice control.
Return Value:
Returns a Dimension object containing the preferred dimensions (in pixels).
Remarks:
The preferred size is based on the associated button's preferred size plus the choice control's insets; an additional 100 pixels are added to the control's width.
public void setSelectedComp(Component comp);Sets the choice control's currently selected item.
Return Value:
No return value.
Parameter Description comp The component to be selected.
© 1997 Microsoft Corporation. All rights reserved. Legal Notices.