Class UIMenuList
public class UIMenuList extends UIList
{
// Constructors
public UIMenuList();
public UIMenuList(int layoutStyle);
// Methods
public boolean action(Event e, Object o);
public IUIMenuLauncher getMenuLauncher();
public boolean gotFocus(Event e, Object o);
public boolean keyDown(Event e, int key);
public boolean lostFocus(Event e, Object o);
public boolean mouseClicked(Event e, int x, int y);
public boolean mouseEnter(Event e, int x, int y);
public void requestFocus();
public void setMenuLauncher(IUIMenuLauncher ml);
}
This class implements a menu list control. Typically, a UIMenuList object is used for the content of a pop-up menu, and is associated with a UIMenuButton control, a UIMenuItem control, or a UIContextMenu control.
A UIMenuList object is empty when it is first created. Using the add method, you can then insert items into the menu list.
Note To insert a separator bar, pass a UILine object to add. The following example shows how to add string items and a separator bar to a menu list.
UIBand menuBar;
UIMenuButton fileButton;
// Create a menu list control.
UIMenuList fileMenu = new UIMenuList();
// Create an array of strings and add each item to the menu.
String fileOptions[] = {"New", "Open", "Close", "Save"};
for (int i=0; i<4; i++)
fileMenu.add(fileOptions[i]);
// Add a separator bar using a UILine object.
// Add a final string after the separator.
fileMenu.add(new UILine());
fileMenu.add("Print");
// Now create the menu button that uses fileMenu
// for its associated pop-up menu.
fileButton = new UIMenuButton("File", fileMenu);
// Create the menu bar and add the menu button.
menuBar = new UIBand();
add(menuBar); // Add the menu bar to the container.
menuBar.add(fileButton);
When the mouse enters a menu item component, its selected state is set and a list select event is generated. When an item is clicked, an action event is generated.
For more information about using UIMenuList objects, see the UIMenuLauncher overview.
UIComponent
|
+--UIContainer
|
+--UIStateContainer
|
+--UIPanel
|
+--UISelector
|
+--UIList
|
+--UIMenuList
public UIMenuList();
Creates an empty menu list control.
Remarks:
Call the add method (inherited through UIList) to add items to the list. By default, the control's selection mode is SINGLESELECT, and the layout style is FILL.
public UIMenuList(int layoutStyle);
Creates an empty menu list control with the specified layout style.
Parameter | Description |
layoutStyle
| The layout style of the control. Possible values include UIVerticalFlowLayout.MULTICOLUMN, UIVerticalFlowLayout.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 its text label is clicked.) Specify 0 for a single-column list with no fill.
|
Remarks:
Call the add method (inherited through UIList) to add items to the list. By default, the control's selection mode is SINGLESELECT.
Exceptions:
IllegalArgumentException
if an undefined layout style was specified.
public boolean action(Event e, Object o);
Updates the choice control to display the currently selected item.
Return Value:
Returns false.
Parameter | Description |
e
| The event posted to the control.
|
o
| 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 is closed.
public IUIMenuLauncher getMenuLauncher();
Retrieves the current menu launcher.
Return Value:
Returns the current menu launcher.
See Also: setMenuLauncher
public boolean gotFocus(Event e, Object o);
Responds to the control receiving input focus.
Return Value:
Returns false.
Parameter | Description |
e
| The event posted to the control.
|
o
| The object that posted the event (typically, null).
|
Remarks:
gotFocus calls UIContainer.gotFocus.
public boolean keyDown(Event e, int key);
Determines whether the DOWN ARROW key is being pressed, and if so, launches the associated menu.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
e
| The event posted to the button.
|
key
| The key that has been pressed.
|
See Also: launch
public boolean lostFocus(Event e, Object o);
Responds to the control, (or any of its descendants), losing input focus.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
e
| The event posted to the control.
|
o
| The object that posted the event (typically, null).
|
public boolean mouseClicked(Event e, int x, int y);
Generates an action event if the mouse button is released over an item that is not a menu launcher object.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
e
| The event posted to the menu list control.
|
x
| The x coordinate of the event.
|
y
| The y coordinate of the event.
|
public boolean mouseEnter(Event e, int x, int y);
Sets the selected state of the item at the mouse's current location. A list select event is generated.
Return Value:
Returns true if the event was handled; otherwise, returns false.
Parameter | Description |
e
| The event posted to the menu list control.
|
x
| The x coordinate of the event.
|
y
| The y coordinate of the event.
|
Remarks:
If the menu item has an associated pop-up menu, its menu is launched.
public void requestFocus();
Requests that the first component associated with the menu list receive focus.
Return Value:
No return value.
public void setMenuLauncher(IUIMenuLauncher ml);
Sets the current UIMenuLauncher to the value passed in. This is a one-to-one relationshipyou cannot assign a UIMenuList to more than one menu launcher at a time.
Return Value:
No return value.
See Also: getMenuLauncher