Package com.ms.ui Previous
Previous
Contents
Contents
Index
Index
Next
Next

Class UIChoice

Constructors , Methods

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);


Constructors


UIChoice

public UIChoice();

Creates an empty choice control.

Remarks:

Call add or addString to add items to the control's pop-up list.


Methods


action

public boolean action(Event e, Object obj);

Updates the choice control to display the currently selected item.

Return Value:

Returns false.

ParameterDescription
e The event posted to the control.
obj The object that posted the event.


add

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.

ParameterDescription
comp The component to be added to the choice control.


addString

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.

ParameterDescription
s The text to be added to the choice control.


getMenu

public UIMenuList getMenu();

Retrieves the choice control's associated pop-up list.

Return Value:

Returns the associated UIMenuList object.


getRoleCode

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.


getSelectedComp

public Component getSelectedComp();

Retrieves the choice control's currently selected item.

Return Value:

Returns the control's selected component.


initGraphics

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.


layout

public void layout();

Lays out the choice control.

Return Value:

No return value.


minimumSize

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.


preferredSize

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.


setSelectedComp

public void setSelectedComp(Component comp);

Sets the choice control's currently selected item.

Return Value:

No return value.

ParameterDescription
comp The component to be selected.



Top© 1997 Microsoft Corporation. All rights reserved. Legal Notices.