Packageorg.aswing
Classpublic class JList
InheritanceJList Inheritance Container Inheritance Component Inheritance AWSprite Inheritance flash.display.Sprite
ImplementsLayoutManager, ListDataListener, Viewportable

A component that allows the user to select one or more objects from a list. A separate model, ListModel, represents the contents of the list. It's easy to display an array objects, using a JList constructor that builds a ListModel instance for you:
 // Create a JList that displays the strings in data[]
  var data:Array = ["one", "two", "three", "four"];
 var dataList:JList = new JList(data);
 
 // The value of the JList model property is an object that provides
 // a read-only view of the data.  It was constructed automatically.
  for(int i = 0; i < dataList.getModel().getSize(); i++) {
     System.out.println(dataList.getModel().getElementAt(i));
 }
  // Create a JList that displays the values in a IVector--VectorListModel.
  var vec:VectorListModel = new VectorListModel(["one", "two", "three", "four"]);
 var vecList:JList = new JList(vec);
 
 //When you add elements to the vector, the JList will be automatically updated.
 vec.append("five");
 

JList doesn't support scrolling directly. To create a scrolling list you make the JList the viewport of a JScrollPane. For example:

 JScrollPane scrollPane = new JScrollPane(dataList);
 // Or in two steps:
 JScrollPane scrollPane = new JScrollPane();
 scrollPane.setView(dataList);
 

By default the JList selection model is SINGLE_SELECTION.

 String[] data = {"one", "two", "three", "four"};
 JList dataList = new JList(data);
  dataList.setSelectedIndex(1);  // select "two"
 dataList.getSelectedValue();   // returns "two"
 

The contents of a JList can be dynamic, in other words, the list elements can change value and the size of the list can change after the JList has been created. The JList observes changes in its model with a ListDataListener implementation. A correct implementation of ListModel notifies it's listeners each time a change occurs. The changes are characterized by a ListDataEvent, which identifies the range of list indices that have been modified, added, or removed. Simple dynamic-content JList applications can use the VectorListModel class to store list elements. This class implements the ListModel and IVector interfaces and provides the Vector API. Applications that need to provide custom ListModel implementations can subclass AbstractListModel, which provides basic ListDataListener support.

JList uses a Component provision, provided by a delegate called the ListCell, to paint the visible cells in the list.

ListCell created by a ListCellFactory, to custom the item representation of the list, you need a custom ListCellFactory. For example a IconListCellFactory create IconListCells.

ListCellFactory is related to the List's performace too, see the doc comments of ListCellFactory for the details. And if you want a horizontal scrollvar visible when item width is bigger than the visible width, you need a not shareCells Factory(and of course the List should located in a JScrollPane first). shareCells Factory can not count the maximum width of list items.

See also

ListCellFactory
ListCell
ListModel
VectorListModel


Public Properties
 PropertyDefined by
 InheritedcacheAsBitmap : Boolean
AWSprite
 Inheritedcontainer : Container
Component
  DND_COPY : int
[static] Drag and drop enabled, and the action of items is copy.
JList
  DND_MOVE : int
[static] Drag and drop enabled, and the action of items is move.
JList
  DND_NONE : int
[static] Drag and drop disabled.
JList
 Inheritedfilters : Array
AWSprite
 Inheritedheight : Number
Component
 Inheritedmask : DisplayObject
AWSprite
  MULTIPLE_SELECTION : int = 1
[static] Can select any item at a time.
JList
 InheritednumChildren : int
AWSprite
  SINGLE_SELECTION : int = 0
[static] Only can select one most item at a time.
JList
 Inheritedvisible : Boolean
Component
 Inheritedwidth : Number
Component
 Inheritedx : Number
Component
 Inheritedy : Number
Component
Protected Properties
 PropertyDefined by
 Inheritedbounds : IntRectangle
Component
  cellPane : CellPane
JList
 Inheritedchildren : Array
Container
 Inheritedd_numChildren : int
AWSprite
 InheriteddrawTransparentTrigger : Boolean = true
Component
 Inheritedd_visible : Boolean
Returns the DisplayObject.visible directly.
Component
 Inheritedd_x : Number
Returns DisplayObject.x directly.
Component
 Inheritedd_y : Number
Returns DisplayObject.y directly.
Component
 Inheritedlayout : LayoutManager
Container
 InheritedreadyToPaint : Boolean
Component
 Inheritedui : ComponentUI
Component
 Inheritedvalid : Boolean
Component
Public Methods
 MethodDefined by
  
JList(listData:* = null, cellFactory:ListCellFactory = null)
Create a list.
JList
 Inherited
addChild(dis:DisplayObject):DisplayObject
Adds a child DisplayObject instance to this DisplayObjectContainer instance.
AWSprite
 Inherited
addChildAt(child:DisplayObject, index:int):DisplayObject
AWSprite
 Inherited
Adds a component to be the acceptable drag initiator to this component.
Component
  
addLayoutComponent(comp:Component, constraints:Object):void
do nothing
JList
  
addSelectionInterval(index0:int, index1:int, programmatic:Boolean = true):void
JList
  
addSelectionListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void
Adds a listener to list selection changed.
JList
  
addStateListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void
Add a listener to listen the viewpoat state change event.
JList
 Inherited
append(com:Component, constraints:Object = null):void
On Component just can add to one Container.
Container
 Inherited
appendAll(... coms):void
Adds one or more component to the container with null constraints
Container
 Inherited
bringToBottom(child:DisplayObject):void
Brings a child to bottom.
AWSprite
 Inherited
bringToTop(child:DisplayObject):void
Brings a child to top.
AWSprite
  
clearSelection(programmatic:Boolean = true):void
Clears the selection - after calling this method isSelectionEmpty will return true.
JList
 Inherited
Component
 Inherited
containsChild(child:DisplayObject):Boolean
Returns whether child is directly child of this sprite, true only if getChildIndex(child) >= 0.
AWSprite
  
data in list has changed, update JList if needed.
JList
 Inherited
doLayout():void
layout this container
Container
  
ensureIndexIsVisible(index:int):void
Scrolls the JList to make the specified cell completely visible.
JList
 Inherited
fireFocusKeyDownEvent(e:KeyboardEvent):void
Component
 Inherited
fireFocusKeyUpEvent(e:KeyboardEvent):void
Component
 Inherited
getAlignmentX():Number
Returns the alignment along the x axis.
Component
 Inherited
getAlignmentY():Number
Returns the alignment along the y axis.
Component
 Inherited
getAlpha():Number
Returns the alpha of this component.
Component
  
Returns the first index argument from the most recent addSelectionModel or setSelectionInterval call.
JList
  
Sets auto drag and drop type.
JList
 Inherited
getAwmlID():String
Returns ID used to identify components created from AWML.
Component
 Inherited
getAwmlIndex():Number
Returns position index of the component inside its AWML container.
Component
 Inherited
Returns namespace name used to identify components created from AWML.
Component
 Inherited
Gets the background color of this component.
Component
 Inherited
Returns the background decorator of this component.
Component
 Inherited
Returns the border.
Component
 Inherited
getBounds(targetCoordinateSpace:DisplayObject):Rectangle
Same to DisplayObject.getBounds(), just add a explaination here that if you want to get the component bounds, see {
Component
  
Returns the cell of the specified index
JList
  
JList
 Inherited
getChildAt(index:int):DisplayObject
AWSprite
 Inherited
getChildByName(name:String):DisplayObject
AWSprite
 Inherited
getChildIndex(child:DisplayObject):int
AWSprite
 Inherited
Returns the value of the property with the specified key.
Component
 Inherited
Returns the clip bounds.
Component
 Inherited

Stores the bounds value of this component into "return value" rv and returns rv.

Component
 Inherited
getComponent(index:int):Component
Gets the nth(index) component in this container.
Container
 Inherited
Gets the number of components in this container.
Container
 Inherited
getConstraints():Object
Gets cpmponent's constraints.
Component
  
JList
  
JList
  
JList
 Inherited
Returns the focus manager for this component's stage, or null if this component is not on stage.
Component
 Inherited
Returns the focus traversal policy of this container, it will return its parent's focus traversal policy if its self is null.
Container
 Inherited
Gets the font of this component.
Component
 Inherited
Gets the foreground color of this component.
Component
 Inherited
Returns the foreground decorator of this component.
Component
 Inherited
Stores the global location value of this component into "return value" p and returns p.
Component
 Inherited
getHeight():int
Returns the current height of this component
Component
 Inherited
Returns the current top index for a new child(none forground child).
AWSprite
  
JList
  
JList
 Inherited
Returns the index of the child component in this container.
Container
 Inherited
If a border has been set on this component, returns the border's insets; otherwise returns an empty insets.
Component
 Inherited
getInternalFocusObject():InteractiveObject
Returns the object to receive the focus for this component.
Component
  
Returns the index of the cell.
JList
 Inherited
Returns the keyboard manager of this component's JRootPane ancestor.
Component
  
JList
 Inherited
Container
  
return 0
JList
  
return 0
JList
  
Returns the second index argument from the most recent addSelectionInterval or setSelectionInterval call.
JList
 Inherited
Stores the location value of this component into "return value" rv and returns rv.
Component
 Inherited
Returns the current bottom index for none background child.
AWSprite
 Inherited
Returns getMaximumSize().height
Component
 Inherited
Component
 Inherited
Returns getMaximumSize().width
Component
 Inherited
Returns getMinimumSize().height
Component
 Inherited
Component
 Inherited
Returns getMinimumSize().width
Component
  
JList
 Inherited
Returns the coordinate of the mouse position, in pixels, in the component scope.
Component
 Inherited
getName():String
Returns the name of the component
Component
 Inherited
Returns the bounds that component should paint in.
Component
 Inherited
Returns the Container parent, if it parent is not a Container, null will be returned.
Component
  
JList
 Inherited
Returns getPreferredSize().height
Component
 Inherited
Component
 Inherited
Returns getPreferredSize().width
Component
 Inherited
Returns the first JRootPane ancestor of this component.
Component
  
Return the selected index, if selection multiple, return the first.
JList
  
Returns an array of all of the selected indices in increasing order.
JList
  
Returns the first selected value, or null if the selection is empty.
JList
  
Returns an array of the values for the selected cells.
JList
  
Returns the background color for selected cells.
JList
  
Returns the foreground color for selected cells.
JList
  
Return whether single-item or multiple-item selections are allowed.
JList
  
Returns the value of the current selection model.
JList
 Inherited
Stores the size value of this component into "return value" rv and returns rv.
Component
 Inherited
getToolTipText():String
Returns the tooltip string that has been set with setToolTipText.
Component
 Inherited
Component
  
getUIClassID():String
JList
  
JList
  
JList
  
JList
  
JList
  
JList
  
Returns the preferred width of visible list pane.
JList
  
Returns the prefferred number of visible rows.
JList
 Inherited
getWidth():int
Returns the current width of this component
Component
 Inherited
getX():int
Returns the current x coordinate of the components.
Component
 Inherited
getY():int
Returns the current y coordinate of the components.
Component
 Inherited
Component
 Inherited
hitTestMouse():Boolean
Returns whether the component hit the mouse.
Component
 Inherited
hitTestObject(obj:DisplayObject):Boolean
AWSprite
 Inherited
hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean
AWSprite
 Inherited
insert(i:int, com:Component, constraints:Object = null):void
Add component to spesified index.
Container
 Inherited
insertAll(index:int, ... coms):void
Insets one or more component to the container with null constraints at specified starting index.
Container
  
data in list has changed, update JList if needed.
JList
  
data in list has changed, update JList if needed.
JList
 Inherited
invalidate():void
Invalidates the container.
Container
  
JList
 Inherited
Clears this component and all parents above it's preferred size caches.
Component
 Inherited
Checks if the component is contained in the component hierarchy of this container.
Container
  
Returns is this list allown to automatically be as an drag and drop target.
JList
  
Returns is this list allown to automatically be as an drag and drop initiator.
JList
 Inherited
Returns whether or not the preferred size, minimum size and max size cache is turned on.
Component
 Inherited
isClipMasked():Boolean
Returns whether the component clip should be masked by its bounds.
AWSprite
 Inherited
Returns whether the component is acceptable drag initiator for this component.
Component
 Inherited
isDragEnabled():Boolean
Returns whether this component can fire ON_DRAG_RECOGNIZED event.
Component
 Inherited
isDropTrigger():Boolean
Returns whether this component can trigger dragging component to fire drag events when dragging over to this component.(Default value is false)
Component
 Inherited
isEnabled():Boolean
Returns whether the component is enabled.
Component
 Inherited
isFocusable():Boolean
Returns whether this Component can be focused.
Component
 Inherited
isFocusableSet():Boolean
Returns whether or not the opaque property is set by user.
Component
 Inherited
isFocusOwner():Boolean
Returns true if this Component is the focus owner.
Component
 Inherited
isFontValidated():Boolean
Returns whether the new font are applied and taked effect.
Component
  
isMutableModel():Boolean
Returns is the source data is acceptale to drop in this list as build-in support
JList
 Inherited
isOnStage():Boolean
Determines whether or not this component is on stage(on the display list).
Component
 Inherited
isOpaque():Boolean
Returns true if this component is completely opaque.
Component
 Inherited
isOpaqueSet():Boolean
Returns whether or not the opaque property is set by user.
Component
  
isSelectedIndex(index:int):Boolean
JList
  
isSelectionEmpty():Boolean
Returns true if nothing is selected.
JList
 Inherited
isShowing():Boolean
Determines whether this component is showing on screen.
Component
  
isTracksWidth():Boolean
Returns tracks width value.
JList
 Inherited
isUIElement():Boolean
Returns true if this component is just a ui element component, false means this component is a regular use created component.
Component
 Inherited
isValid():Boolean
Determines whether this component is valid.
Component
 Inherited
isValidateRoot():Boolean
If this method returns true, revalidate calls by descendants of this component will cause the entire tree beginning with this root to be validated.
Component
 Inherited
isVisible():Boolean
Component
  
position and fill cells here
JList
 Inherited
makeFocus():void
Makes this component's internal focus object to be the stage focus directly, without any judgement.
Component
  
JList
  
JList
 Inherited
pack():void
Causes this component to be sized to fit the preferred size.
Component
 Inherited
paintFocusRect(force:Boolean = false):void
Paints the focus rect if need.
Component
 Inherited
Redraw the component UI face immediately if it is visible and ready to paint.
Component
 Inherited
Calls parent reAppendChildren if parent is a container.
Component
  
JList
 Inherited
putClientProperty(key:*, value:*):void
Adds an arbitrary key/value "client property" to this component.
Component
 Inherited
Removes all children and then append them with their constraints.
Container
 Inherited
reAppendToParent(constraints:Object = null):void
Removes this component from its parent and then append it with specified constraints.
Component
 Inherited
Remove the specified child component.
Container
 Inherited
removeAll():void
Remove all child components.
Container
 Inherited
Remove the specified index child component.
Container
 Inherited
removeChild(child:DisplayObject):DisplayObject
Removes a normal display object child.
Container
 Inherited
removeChildAt(index:int):DisplayObject
Removes a normal display object child with index.
Container
 Inherited
Removes a component to be the acceptable drag initiator to this component.
Component
 Inherited
Removes this component from its parent, whatever it is as a component child or only a display object child, or it's parent is just a display object container.
Component
  
do nothing
JList
  
removeSelectionInterval(index0:int, index1:int, programmatic:Boolean = true):void
JList
  
removeSelectionListener(listener:Function):void
Removes a listener from list selection changed listeners.
JList
  
removeStateListener(listener:Function):void
Removes a state listener.
JList
 Inherited
repaint():void
Redraws the component face next RENDER event.This method can be called often, so it needs to execute quickly.
Component
 Inherited
Component
 Inherited
requestFocus():Boolean
Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window.
Component
 Inherited
revalidate():void
Supports deferred automatic layout.
Component
 Inherited
Component
  
scrollRectToVisible(contentRect:IntRectangle, programmatic:Boolean = true):void
JList
  
Scrolls to view bottom left content.
JList
  
Scrolls to view bottom right content.
JList
  
Scrolls to view top left content.
JList
  
Scrolls to view to right content.
JList
  
selectAll(programmatic:Boolean = true):void
Selects all elements in the list.
JList
 Inherited
setAlignmentX(ax:Number):void
Component
 Inherited
setAlignmentY(ay:Number):void
Component
 Inherited
setAlpha(alpha:Number):void
Indicates the alpha transparency value of the component.
Component
 Inherited
setAwmlID(id:String):void
Sets ID used to identify components created from AWML.
Component
 Inherited
setAwmlIndex(index:Number):void
Sets ID used to identify components created from AWML.
Component
 Inherited
setAwmlNamespace(theNamespace:String):void
Sets namespace used to identify components created from AWML.
Component
 Inherited
Sets the background color of this component.
Component
 Inherited
Sets a decorator to be the component background, it will represent the component background with a DisplayObject.
Component
 Inherited
setBorder(b:Border):void
Sets the border for the component, null to remove border.
Component
 Inherited
This method will call setComBounds()
Component
 Inherited
setCachePreferSizes(b:Boolean):void
Sets whether or not turn on the preferred size, minimum size and max size cache.
Component
  
This will cause all cells recreating by new factory.
JList
 Inherited
setChildIndex(child:DisplayObject, index:int):void
AWSprite
 Inherited
Sets the clip bounds, a rectangle mask to make specified bounds visible.
Component
 Inherited
setClipMasked(m:Boolean):void
Sets whether the component clip should be masked by its bounds.
AWSprite
 Inherited
Sets the clip size, a rectangle mask to make specified bounds visible.
Component
 Inherited
Moves and resizes this component.
Component
&n