Packages
 In this topic

*Constructors

*Methods

*Fields

 

Packages   PreviousThis PackageNext
Package com.ms.ui   Previous This
Package
Next

 


Class UIChoice

public class UIChoice extends UIPanel implements IUISelector
{
  // Fields
  public static final int THICK;

  // Constructors
  public UIChoice();

  // Methods
  public boolean action(Event e, Object obj);
  public IUIComponent add(IUIComponent comp);
  public void addActionListener(IUIActionListener l);
  public synchronized void addItemListener(IUIItemListener l);
  public void addNotify();
  public void addSelectedIndex(int index);
  public void addSelectedIndex(int index, boolean notify);
  public void addSelectedIndices(int indices[]);
  public void addSelectedIndices(int indices[], boolean notify);
  public void addSelectedItem(IUIComponent comp);
  public void addSelectedItem(IUIComponent comp, boolean notify);
  public void addSelectedItems(IUIComponent comps[]);
  public void addSelectedItems(IUIComponent comps[],
        boolean notify);
  public IUIComponent addString(String s);
  public IUIComponent getAnchorItem();
  public IUIComponent getExtensionItem();
  public UIMenuList getMenu();
  public Dimension getPreferredSize();
  public int getRoleCode();
  public int[] getSelectedIndices();
  public IUIComponent getSelectedItem();
  public IUIComponent[] getSelectedItems();
  public int getSelectionMode();
  public int getStyle();
  public String getValueText();
  public boolean handleEvent(Event e);
  public boolean keyDown(Event e, int key);
  public void layout();
  public boolean mouseDown(Event e, int x, int y);
  public boolean postEvent(Event e);
  protected void processEvent(UIEvent e);
  protected void processItemEvent(UIItemEvent e);
  public void remove(IUIComponent comp);
  public void removeActionListener(IUIActionListener l);
  public synchronized void removeItemListener(IUIItemListener l);
  public void removeSelectedIndex(int index);
  public void removeSelectedIndex(int index, boolean notify);
  public void removeSelectedIndices(int indices[]);
  public void removeSelectedIndices(int indices[], boolean notify);
  public void removeSelectedItem(IUIComponent comp);
  public void removeSelectedItem(IUIComponent comp, boolean notify);
  public void removeSelectedItems(IUIComponent comps[]);
  public void removeSelectedItems(IUIComponent comps[],
        boolean notify);
  public void requestFocus();
  public void setAnchorItem(IUIComponent comp);
  public void setExtensionItem(IUIComponent comp);
  public void setSelectedIndex(int index);
  public void setSelectedIndex(int index, boolean notify);
  public void setSelectedIndices(int indices[]);
  public void setSelectedIndices(int indices[], boolean notify);
  public void setSelectedItem(IUIComponent comp);
  public void setSelectedItem(IUIComponent comp, boolean notify);
  public void setSelectedItems(IUIComponent comps[]);
  public void setSelectedItems(IUIComponent comps[],
        boolean notify);
  public void setSelectionMode(int mode);
  public void setStyle(int style);
  public void setValueText(String s);
}

This class implements a choice control (combo box). A UIChoice object manages the components listed in the following table. In general, any IUIComponent can be added to the menu list. If the IUIComponent is not an IUIContainer, for example, it is a UIItem or UIText, an exact copy of this item appears in the choice display when the item is selected. If an IUIContainer component is used, for example, UIPanel, the name of that container is used in display component, instead of a copy of the actual container. Use getSelectedItem to retrieve the container.

This class supports event listeners.

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.
IUIComponent 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 shown in the following example.

// Construct a UIChoice object.
UIChoice c = new UIChoice();

// Create an array of components. When items are added to
// the choice control, these array values will hold the
// components returned from addString.
IUIComponent comps[] = new IUIComponent[4];

// Create an array of strings and add each
// element to the choice control.
String colors[] = {"Red", "Blue", "Green", "Black"};
for (int i=0; i<4; i++)
   comps[i] = c.addString(colors[i]);

// Add the control to the container. 
uiec.addSelectedItems(comps);

Note Although UIChoice operates only in SINGLESELECT mode, it implements the IUISelector interface, which has "pluralized" methods, such as getSelectedItems and setSelectedIndices. An IllegalArgumentException is thrown more if an attempt is made to select more than one item. The methods getSelectedIndices/Items simply returns arrays of length 1.

To remove items from a UIChoice menu, use one of the following methods. Call UIChoice.remove(IUIComponent comp) where the comp is the component to be moved from the menu. Or, obtain the UIChoice menu using UIChoice.getMenu, and call any remove method on the menu itself. If UIChoice.remove(int index) is used, components will be removed from the UIChoice control itself, like the menu launcher button.

Also see getSelectedIndex, getSelectedItem

UIComponent
  |
  +--UIContainer
    |
    +--UIStateContainer
      |
      +--UIPanel
        |
        +--UIChoice

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.

Remarks:

An action event is generated when an item in the control's pop-up list is selected, and the pop-up list is closed.

add

public IUIComponent add(IUIComponent 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.

See Also: addString

addActionListener

public void addActionListener(IUIActionListener l);

Adds the specified action listener. The listener receives all action events generated for the control.

Return Value:

No return value.

ParameterDescription
l The action listener to be added.

addItemListener

public synchronized void addItemListener(IUIItemListener l);

Adds the specified item listener. The listener receives all item events generated for the control. (Item events are generated when the state of an item changes.)

Return Value:

No return value.

ParameterDescription
l The item listener to be added.

See Also: removeItemListener

addNotify

public void addNotify();

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.

addSelectedIndex

public void addSelectedIndex(int index);

Selects the component at the specified index, without affecting other selections. By default, list select events are not generated.

Return Value:

No return value.

ParameterDescription
index The zero-based index of the item to be selected.

addSelectedIndex

public void addSelectedIndex(int index, boolean notify);

Selects the component at the specified index, without affecting other selections. Optionally generates list select events.

Return Value:

No return value.

ParameterDescription
index The zero-based index of the item to be selected.
notify If true, list select events will be generated; otherwise, list select events will not be generated.

addSelectedIndices

public void addSelectedIndices(int indices[]);

Selects the components at the specified indices, without affecting other selections. By default, list select events are not generated.

Return Value:

No return value.

ParameterDescription
indices An array containing the indices of the items to be selected.

addSelectedIndices

public void addSelectedIndices(int indices[], boolean notify);

Selects the components at the specified indices, without affecting other selections. Optionally generates list select events.

Return Value:

No return value.

ParameterDescription
indices An array containing the indices of the items to be selected.
notify If true, list select events will be generated; otherwise, list select events will not be generated.

addSelectedItem

public void addSelectedItem(IUIComponent comp);

Selects the specified component, without affecting other selections. By default, list select events are not generated.

Return Value:

No return value.

ParameterDescription
comp The component to be selected.

addSelectedItem

public void addSelectedItem(IUIComponent comp, boolean notify);

Selects the specified component, without affecting other selections. Optionally generates list select events.

Return Value:

No return value.

ParameterDescription
comp The component to be selected.
notify If true, list select events will be generated; otherwise, list select events will not be generated.

addSelectedItems

public void addSelectedItems(IUIComponent comps[]);

Selects the specified components, without affecting other selections. By default, list select events are not generated.

Return Value:

No return value.

ParameterDescription
comps An array containing the components to be selected.

addSelectedItems

public void addSelectedItems(IUIComponent comps[], boolean notify);

Selects the specified components, without affecting other selections. Optionally generates list select events.

Return Value:

No return value.

ParameterDescription
comps An array containing the component to be selected.
notify If true, list select events will be generated; otherwise, list select events will not be generated.

addString

public IUIComponent 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.

See Also: add

getAnchorItem

public IUIComponent getAnchorItem();

Retrieves the component that is the current anchor in extend select mode.

Return Value:

Returns the component that is the anchor.

getExtensionItem

public IUIComponent getExtensionItem();

Retrieves the last item (the extension item) that was (CTRL)+SHIFT+clicked in EXTENDSELECT mode.

Return Value:

Returns the extension item.

getMenu

public UIMenuList getMenu();

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

Return Value:

Returns the associated UIMenuList object.

getPreferredSize

public Dimension getPreferredSize();

Determines the preferred size (in pixels) of the choice control. The UIChoice preferred size is just large enough to accommodate the largest of the items in its menu. If you want to have the UIChoice sized differently, use a layout manager that ignores getPreferredSize.

Return Value:

Returns a Dimension object containing the preferred size.

Remarks:

The choice control's preferred size is based on the associated button's preferred size, the control's insets, and the largest preferred size of all the associated menu's children.

getRoleCode

public int getRoleCode();

Retrieves the ROLE_SYSTEM code that best describes the role of the choice control.

Return Value:

Returns the ROLE_SYSTEM_COMBOBOX code.

getSelectedIndices

public int[] getSelectedIndices();

Retrieves the zero-based indices of all currently selected items.

Return Value:

Returns an array of the indices of the selected items, if an item is selected; otherwise, returns null.

getSelectedItem

public IUIComponent getSelectedItem();

Retrieves the currently selected item of the choice control.

Return Value:

Returns the selected component, if a component is selected; otherwise, returns null.

Remarks:

If the control's selection mode is MULTISELECT or EXTENDSELECT, you can also call getSelectedItems.

getSelectedItems

public IUIComponent[] getSelectedItems();

Retrieves all currently selected items.

Return Value:

Returns an array of the selected components, if a component is selected; otherwise, returns null.

getSelectionMode

public int getSelectionMode();

Retrieves the selection mode of the control.

Return Value:

Returns one of the following three selection modes: SINGLESELECT, MULTISELECT, or EXTENDSELECT.

getStyle

public int getStyle();

Retrieves the current style of the control.

Return Value:

Returns an integer containing the current style setting. For a list of possible values, see setStyle.

getValueText

public String getValueText();

Retrieves the name of the currently selected item.

Return Value:

Returns the name of the currently selected item.

handleEvent

public boolean handleEvent(Event e);

Updates the display box each time a list select event happens.

Return Value:

Returns false.

ParameterDescription
e The LIST_SELECT event.

keyDown

public boolean keyDown(Event e, int key);

Determines whether the SPACEBAR or the ENTER key is being pressed, and if so, sets the pressed state.

Return Value:

Returns true if the event was handled; otherwise, returns false.

ParameterDescription
e The event posted to the button control.
key The key that has been pressed.

Remarks:

This method is called when the button has focus and a key is pressed. If the key being pressed is the SPACEBAR or the ENTER key, the button's pressed state is set. If the ESC key is being pressed, the button's pressed state is cleared.

For more information about states, see the UIStateContainer overview.

See Also: keyUp

layout

public void layout();

Lays out the choice control.

Return Value:

No return value.

mouseDown

public boolean mouseDown(Event e, int x, int y);

Responds to the mouse button being pressed over the control.

Return Value:

Returns true if the event was handled, false otherwise.

ParameterDescription
e The event posted to the control.
x The x coordinate of the event.
y The y coordinate of the event.

Remarks:

This method calls UIComponent.mouseDown.

postEvent

public boolean postEvent(Event e);

Posts the specified event to the control.

Return Value:

Returns true if the event was posted; otherwise, returns false.

ParameterDescription
e The event to post.

Remarks:

If the event's target is the button component, this method changes the target to the choice control itself before posting the event.

processEvent

protected void processEvent(UIEvent e);

Processes the specified event.

Return Value:

No return value.

ParameterDescription
e The event.

Remarks:

This method is automatically invoked if a listener has been registered through a call to addXXXListener. Depending on the type of event, processEvent calls one of the following methods.

Event type Method called
item event processItemEvent
container event processContainerEvent (inherited through UIStateContainer)
focus event processFocusEvent (inherited through UIStateContainer)
key event processKeyEvent (inherited through UIStateContainer)
mouse event processMouseEvent (inherited through UIStateContainer)
mouse motion event processMouseMotionEvent (inherited through UIStateContainer)

When overriding processEvent, call the super method processEvent to ensure the default event processing continues normally.

processItemEvent

protected void processItemEvent(UIItemEvent e);

Processes item events.

Return Value:

No return value.

ParameterDescription
e The item event.

Remarks:

This method is called by processEvent and dispatches the event to a registered item listener. When overriding this method, call the super method processItemEvent to ensure the default event processing continues normally.

See Also: addItemListener

remove

public void remove(IUIComponent comp);

Removes the specified component from the choice control's associated pop-up list.

Return Value:

No return value.

ParameterDescription
comp The component to be removed.

removeActionListener

public void removeActionListener(IUIActionListener l);

Removes the specified action listener. The listener no longer receives the control's action events.

Return Value:

No return value.

ParameterDescription
l The action listener to be removed.

removeItemListener

public synchronized void removeItemListener(IUIItemListener l);

Removes the specified item listener. The listener no longer receives the control's item events.

Return Value:

No return value.

ParameterDescription
l The item listener to be removed.

See Also: addItemListener

removeSelectedIndex

public void removeSelectedIndex(int index);

Deselects the component at the specified index, without affecting other selections. By default, list deselect events are not generated.

Return Value:

No return value.

ParameterDescription
index The zero-based index of the item to be deselected.

removeSelectedIndex

public void removeSelectedIndex(int index, boolean notify);

Deselects the component at the specified index, without affecting other selections. Optionally generates list select events.

Return Value:

No return value.

ParameterDescription
index The zero-based index of the item to be deselected.
notify If true, list deselect events will be generated; otherwise, list deselect events will not be generated.

removeSelectedIndices

public void removeSelectedIndices(int indices[]);

Deselects the components at the specified indices, without affecting other selections. By default, list deselect events are not generated.

Return Value:

No return value.

ParameterDescription
indices An array containing the indices of the items to be deselected.

removeSelectedIndices

public void removeSelectedIndices(int indices[], boolean notify);

Deselects the components at the specified indices, without affecting other selections. Optionally generates list deselect events.

Return Value:

No return value.

ParameterDescription
indices An array containing the indices of the items to be deselected.
notify If true, list deselect events will be generated; otherwise, list deselect events will not be generated.

removeSelectedItem

public void removeSelectedItem(IUIComponent comp);

Deselects the specified component, without affecting other selections. By default, list deselect events are not generated.

Return Value:

No return value.

ParameterDescription
comp The component to be deselected.

removeSelectedItem

public void removeSelectedItem(IUIComponent comp, boolean notify);

Deselects the specified component, without affecting other selections. Optionally generates list deselect events.

Return Value:

No return value.

ParameterDescription
comp The component to be deselected.
notify If true, list deselect events will be generated; otherwise, list deselect events will not be generated.

removeSelectedItems

public void removeSelectedItems(IUIComponent comps[]);

Deselects the specified components, without affecting other selections. By default, list deselect events are not generated.

Return Value:

No return value.

ParameterDescription
comps An array containing the components to be deselected.

removeSelectedItems

public void removeSelectedItems(IUIComponent comps[], boolean notify);

Deselects the specified components, without affecting other selections. Optionally generates list deselect events.

Return Value:

No return value.

ParameterDescription
comps An array containing the component to be deselected.
notify If true, list deselect events will be generated; otherwise, list deselect events will not be generated.

requestFocus

public void requestFocus();

Responds to the control that is receiving input focus.

Return Value:

No return value.

Remarks:

requestFocus calls UIContainer.requestFocus.

setAnchorItem

public void setAnchorItem(IUIComponent comp);

Sets the item used as an anchor in EXTENDSELECT mode. The anchor item cannot be set to null.

Note Resetting the anchor automatically sets the current extension item to null. If it is intended to set both to specific items, call setAnchorItem, followed by setExtensionItem.

Setting the anchor in an IUISelector other than the outermost one, has no effect.

Return Value:

No return value.

ParameterDescription
comp The component that will be the new anchor.

Exceptions:

IllegalArgumentException if the component is not a child of the selector, or if the component is null.

setExtensionItem

public void setExtensionItem(IUIComponent comp);

Sets the item to which a selection extends from an anchor.

Note Calling setAnchorItem automatically resets this item to null.

Return Value:

No return value.

ParameterDescription
comp The component that will be the new extension item.

Exceptions:

IllegalArgumentException if the component is not a child of the selector.

setSelectedIndex

public void setSelectedIndex(int index);

Sets the selection to the component at the specified index. By default, a list select event is not generated.

Return Value:

No return value.

ParameterDescription
index The zero-based index of the item to be selected.

Remarks:

This method clears any previous selection.

setSelectedIndex

public void setSelectedIndex(int index, boolean notify);

Sets the selection to the component at the specified index, and optionally generates a list select event.

Return Value:

No return value.

ParameterDescription
index The zero-based index of the item to be selected.
notify If true, a list select event will be generated; otherwise, a list select event will not be generated.

Remarks:

This method clears any previous selection.

setSelectedIndices

public void setSelectedIndices(int indices[]);

Sets the selection to the components at the specified indices. By default, list select events are not generated.

Return Value:

No return value.

ParameterDescription
indices An array containing the indices of the items to be selected.

Remarks:

This method clears any previous selection.

setSelectedIndices

public void setSelectedIndices(int indices[], boolean notify);

Sets the selection to the components at the specified indices, and optionally generates list select events.

Return Value:

No return value.

ParameterDescription
indices An array containing the indices of the items to be selected.
notify If true, list select events will be generated; otherwise, list select events will not be generated.

Remarks:

This method clears any previous selection.

setSelectedItem

public void setSelectedItem(IUIComponent comp);

Sets the selection to the specified component. By default, a list select event is not generated. To be notified when a new selection is made, override this method and call the super method setSelectedItem(comp).

Return Value:

No return value.

ParameterDescription
comp The item to be selected.

Remarks:

This method clears any previous selection.

setSelectedItem

public void setSelectedItem(IUIComponent comp, boolean notify);

Sets the selection to the specified component, and optionally generates a list select event. To be notified when a new selection is made, override this method and call the super method setSelectedItem(comp, notify).

Return Value:

No return value.

ParameterDescription
comp The item to be selected.
notify If true, a list select event will be generated; otherwise, a list select event will not be generated.

Remarks:

This method clears any previous selection.

setSelectedItems

public void setSelectedItems(IUIComponent comps[]);

Sets the selection to the specified components. By default, list select events are not generated.

Return Value:

No return value.

ParameterDescription
comps An array containing the items to be selected.

Remarks:

This method clears any previous selection.

setSelectedItems

public void setSelectedItems(IUIComponent comps[], boolean notify);

Sets the selection to the specified components, and optionally generates list select events.

Return Value:

No return value.

ParameterDescription
comps An array containing the items to be selected.
notify If true, list select events will be generated; otherwise, list select events will not be generated.

Remarks:

This method clears any previous selection.

setSelectionMode

public void setSelectionMode(int mode);

Sets the selection mode of the control.

Return Value:

No return value.

ParameterDescription
mode The selection mode for the control. Only the SINGLESELECT mode is supported for UIChoice.

Exceptions:

IllegalArgumentException If a mode other than SINGLESELECT is used.

setStyle

public void setStyle(int style);

Sets the current style for the component.

Return Value:

No return value.

ParameterDescription
style The style of the component. You can pass THICK to specify a thick border around the component and its elements. To return the style to the default, call setStyle(0).

Exceptions:

IllegalArgumentException if an undefined style was specified.

setValueText

public void setValueText(String s);

Searches the UIChoice control for an item whose name matches that of the string. If that item is found, it becomes the selected item.

Return Value:

No return value.

ParameterDescription
s The string that contains the name of the control.

Fields

THICK
Specifies that the button has a thick edge.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.