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

Class UIList

Constructors , Methods

public class UIList extends UISelector
{
  // Constructors
  public UIList();
  public UIList(int selMode);
  public UIList(int selMode, int layoutStyle);

  // Methods
  public Component add(String s);
  public Component add(String s, int pos);

}

A class that implements a list control. A UIList object can have a SINGLESELECT, MULTISELECT, or EXTENDSELECT selection mode. By default, UIList uses UIVerticalFlowLayout for its layout manager, which provides support for multi-column list controls. The following example shows different ways to construct a UIList object.

// Construct a list control that allows multiple
// items to be selected with the SHIFT key.
UIList lst1 = new UIList(UIList.EXTENDSELECT);

// Construct a single-selection, multi-column list control.
UIList lst2 = 
   new UIList(UIList.SINGLESELECT, UIVerticalFlowLayout.MULTICOLUMN);

A UIList object is initially empty when it is first created. The add method allows you to insert text items into the list control, as shown in the following example.

// Create an array of Strings.
String fruit[] = {"Apple", "Banana", "Cherry", "Kiwi"};

// Add each item in the array to lst1.
for (int i=0; i<4; i++)
  lst1.add(fruit[i]);

// Now add lst1 to the container.
add(lst1);

By default, a LIST_SELECT event is generated when an item in the list control is clicked. (An ACTION_EVENT is generated when an item is double-clicked.) You can trap for this event by overriding the handleEvent method, as shown in the following example.

public boolean handleEvent(Event e)
{
   if (e.id == Event.LIST_SELECT)
   {
      if (e.target == lst1)
      {
         // Determine whether the first item in lst1 
         // was selected. cb1 is a UICheckButton object.
         if (lst1.getSelectedIndex() == 0)
            cb1.setChecked(true);
         else
            cb1.setChecked(false);

         return (true);
      }
      else if (e.target == lst2)
      {
         // Set the check box label to the item 
         // selected in lst2.
         cb1.setName(lst2.getSelectedItem().getName());
         return (true);
      }
   }
   return (false);
}

Note that UIList objects alone have no scrolling capabilities. Typically, you'll create a UIScrollViewer object to contain your list control. UIScrollViewer inserts scroll bars when necessary. The following example adds a list control to a UIScrollViewer object.

UIList myList = new UIList();
myList.add("first item"); // Add an item to myList.
...  // Continue adding items to myList.

// Now create a UIScrollViewer object to contain myList. 
UIScrollViewer sv = new UIScrollViewer(myList);

// Add sv to the container.
add(sv);

UIList extends UISelector.


Constructors


UIList

public UIList();

Creates an empty list control.

Remarks:

Call the add method to add items to the list. By default, the list control is a single-selection, single-column list.


UIList

public UIList(int selMode);

Creates an empty list control with the specified selection mode.

ParameterDescription
selMode The selection mode of the control. Specify SINGLESELECT, MULTISELECT, or EXTENDSELECT.

Remarks:

Call the add method to add items to the list. By default, the list control is a single-column list. If an undefined selection mode is specified, an IllegalArgumentException is thrown.


UIList

public UIList(int selMode, int layoutStyle);

Creates an empty list control with the specified selection mode and layout style.

ParameterDescription
selMode The selection mode of the control. Specify SINGLESELECT, MULTISELECT, or EXTENDSELECT.
layoutStyle The layout style of the control. Specify UIVerticalFlowLayout.MULTICOLUMN, UIVeritcalFlowLayout.FILL, or a bitwise combination of the two. (FILL extends the width of an item to the width of the list control; this allows the item to be selected even when the area outside of its text label is clicked.) Specify 0 for a single-column list with no fill.

Remarks:

Call the add method to add items to the list. If an undefined selection mode or layout style is specified, an IllegalArgumentException is thrown.


Methods


add

public Component add(String s);

Adds the specified text to the end of the list.

Return Value:

Returns the text component that was added.

ParameterDescription
s The text to be added.


add

public Component add(String s, int pos);

Adds the specified text to the list at the specified position.

Return Value:

Returns the text component that was added.

ParameterDescription
s The text to be added.
pos The indexed position at which to add the text. The first position is identified by 0; the end of the list is identified by -1.



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