class org.aswing.JList extends Container

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 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 this.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 scrollbar visible when item width is bigger than the visible width, you need a not ListCellFactory.isShareCells Factory(and of course the List should located in a JScrollPane first). ListCellFactory.isShareCells Factory can not count the maximum width of list items. @author paling @see ListCellFactory @see ListCell @see ListModel @see VectorListModel

Class Fields

static var AUTO_INCREMENT:Int

The default unit/block increment, it means auto count a value.

static var DND_COPY:Int

Drag and drop enabled, and the action of items is copy.

static var DND_MOVE:Int

Drag and drop enabled, and the action of items is move.

static var DND_NONE:Int

Drag and drop disabled.

static var MULTIPLE_SELECTION:Int

Can select any item at a time.

static var SINGLE_SELECTION:Int

Only can select one most item at a time.

Instance Fields

Show inherited public instance fieldsHide inherited public instance fields

Inherited from Container

var layout:LayoutManager
function append(com:Component, ?constraints:Dynamic):Void
function appendAll(coms:Array<Dynamic>):Void
function doLayout():Void
function getComponent(index:Int):Component
function getComponentCount():Int
function getComponents():Array<Dynamic>
function getFocusTraversalPolicy():FocusTraversalPolicy
function getIndex(com:Component):Int
function getLayout():LayoutManager
function insert(i:Int, com:Component, ?constraints:Dynamic):Void
function insertAll(index:Int, coms:Array<Dynamic>):Void
function invalidate():Void
function isAncestorOf(c:Component):Bool
function reAppendChildren():Void
function remove(com:Component):Component
function removeAll():Void
function removeAt(i:Int):Component
function removeChild(child:DisplayObject):DisplayObject
function removeChildAt(index:Int):DisplayObject
function setFocusTraversalPolicy(ftp:FocusTraversalPolicy):Void
function setLayout(layout:LayoutManager):Void
function validate():Void

Inherited from Component

var __fieldBindings__:FieldsBindSignal
var __methodBindings__:MethodsBindSignal
var alignmentX:Float
var alignmentY:Float
var background:ASColor
var backgroundDecorator:GroundDecorator
var border:Border
var bounds:IntRectangle
var clipBounds:IntRectangle
var constraints:Dynamic
var currentSize:IntDimension
var dragEnabled:Bool
var dropTrigger:Bool
var enabled:Bool
var focusable:Bool
var focusableSet:Bool
var font:ASFont
var foreground:ASColor
var foregroundDecorator:GroundDecorator
var location:IntPoint
var maximumSize:IntDimension
var mideground:ASColor
var minimumSize:IntDimension
var opaque:Bool
var opaqueSet:Bool
var preferredSize:IntDimension
var resizerMargin:Insets
var styleProxy:Component
var styleTune:StyleTune
var toolTipText:String
var transitFocusFactor:Float
var ui:ComponentUI
var uiElement:Bool
var visibility:Bool
function addDragAcceptableInitiator(com:Component):Void
function componentToGlobal(p:IntPoint):IntPoint
function getClientProperty(key:String, ?defaultValue:Dynamic):Dynamic
function getDefaultBasicUIClass():Class<Dynamic>
function getFocusManager():FocusManager
function getGlobalLocation(?rv:IntPoint):IntPoint
function getInsets():Insets
function getInternalFocusObject():InteractiveObject
function getKeyboardManager():KeyboardManager
function getMousePosition():IntPoint
function getPaintBounds():IntRectangle
function getParent():Container
function getRootPaneAncestor():JRootPane
function getUIClassID():String
function globalToComponent(p:IntPoint):IntPoint
function hitTestMouse():Bool
function invalidate():Void
function invalidatePreferSizeCaches():Void
function isCachePreferSizes():Bool
function isDragAcceptableInitiator(com:Component):Bool
function isFocusOwner():Bool
function isFontValidated():Bool
function isOnStage():Bool
function isShowing():Bool
function isValid():Bool
function isValidateRoot():Bool
function makeFocus():Void
function pack():Void
function paintFocusRect(?force:Bool):Void
function paintImmediately():Void
function parentReAppendChildren():Void
function putClientProperty(key:String, value:Dynamic):Void
function reAppendToParent(?constraints:Dynamic):Void
function removeDragAcceptableInitiator(com:Component):Void
function removeFromContainer():Void
function repaint():Void
function repaintAndRevalidate():Void
function requestFocus():Bool
function revalidate():Void
function setCachePreferSizes(b:Bool):Void
function setClipSize(size:IntDimension):Void
function setDragAcceptableInitiatorAppraiser(func:Dynamic ->Bool):Void
function setFontValidated(b:Bool):Void
function setGlobalLocation(gp:IntPoint):Void
function transferFocus():Bool
function transferFocusBackward():Bool
function updateUI():Void
function validate():Void

Inherited from AWSprite

function bringToBottom(child:DisplayObject):Void
function bringToTop(child:DisplayObject):Void
function containsChild(child:DisplayObject):Bool
function getHighestIndexUnderForeground():Int
function getLowestIndexAboveBackground():Int
function isClipMasked():Bool
function setChildIndex(child:DisplayObject, index:Int):Void
function setClipMaskRect(b:IntRectangle):Void
function setClipMasked(m:Bool):Void
function toString():String

Inherited from Sprite

var buttonMode:Bool
var dropTarget:DisplayObject
var graphics:Graphics
var hitArea:Sprite
var soundTransform:SoundTransform
var useHandCursor:Bool
function startDrag(?lockCenter:Bool, ?bounds:Rectangle):Void
function startTouchDrag(touchPointID:Int, ?lockCenter:Bool, ?bounds:Rectangle):Void
function stopDrag():Void
function stopTouchDrag(touchPointID:Int):Void

Inherited from DisplayObjectContainer

var mouseChildren:Bool
var numChildren:Int
var tabChildren:Bool
var textSnapshot:TextSnapshot
function addChild(child:DisplayObject):DisplayObject
function addChildAt(child:DisplayObject, index:Int):DisplayObject
function areInaccessibleObjectsUnderPoint(point:Point):Bool
function contains(child:DisplayObject):Bool
function getChildAt(index:Int):DisplayObject
function getChildByName(name:String):DisplayObject
function getChildIndex(child:DisplayObject):Int
function getObjectsUnderPoint(point:Point):Array<DisplayObject>
function removeChild(child:DisplayObject):DisplayObject
function removeChildAt(index:Int):DisplayObject
function setChildIndex(child:DisplayObject, index:Int):Void
function swapChildren(child1:DisplayObject, child2:DisplayObject):Void
function swapChildrenAt(index1:Int, index2:Int):Void

Inherited from InteractiveObject

var accessibilityImplementation:AccessibilityImplementation
var contextMenu:ContextMenu
var doubleClickEnabled:Bool
var focusRect:Dynamic
var mouseEnabled:Bool
var tabEnabled:Bool
var tabIndex:Int

Inherited from DisplayObject

var accessibilityProperties:AccessibilityProperties
var alpha:Float
var blendMode:BlendMode
var blendShader:Shader
var cacheAsBitmap:Bool
var filters:Array<BitmapFilter>
var height:Float
var loaderInfo:LoaderInfo
var mask:DisplayObject
var mouseX:Float
var mouseY:Float
var name:String
var opaqueBackground:Null<UInt>
var parent:DisplayObjectContainer
var root:DisplayObject
var rotation:Float
var rotationX:Float
var rotationY:Float
var rotationZ:Float
var scale9Grid:Rectangle
var scaleX:Float
var scaleY:Float
var scaleZ:Float
var scrollRect:Rectangle
var stage:Stage
var transform:Transform
var visible:Bool
var width:Float
var x:Float
var y:Float
var z:Float
function getBounds(targetCoordinateSpace:DisplayObject):Rectangle
function getRect(targetCoordinateSpace:DisplayObject):Rectangle
function globalToLocal(point:Point):Point
function globalToLocal3D(point:Point):Vector3D
function hitTestObject(obj:DisplayObject):Bool
function hitTestPoint(x:Float, y:Float, ?shapeFlag:Bool):Bool
function local3DToGlobal(point3d:Vector3D):Point
function localToGlobal(point:Point):Point

Inherited from EventDispatcher

function addEventListener(type:String, listener:Dynamic ->Void?useCapture:Bool, ?priority:Int, ?useWeakReference:Bool):Void
function dispatchEvent(event:Event):Bool
function hasEventListener(type:String):Bool
function removeEventListener(type:String, listener:Dynamic ->Void?useCapture:Bool):Void
function toString():String
function willTrigger(type:String):Bool

var cellFactory:ListCellFactory

A cell factory for this List

Setting will cause all cells recreating by new factory. @see ListCellFactory

var fitWidth:Bool

True to make the cell always have same width with the List container, and the horizontal scrollbar will not shown if the list is in a JScrollPane;

  *

False to make it as same as its preffered width.

var model:ListModel

The list model to provide the data to JList. @see org.aswing.ListModel

var preferredWidthWhenNoCount:Int

The preferred with of the List, it is only used when List have no counting for its prefferredWidth.

When ListCellFactory.isShareCells == true, List will not count prefferred width.

var selectedIndex:Int

A single selected cell. @see ListSelectionModel#setSelectionInterval @see #isSelectedIndex() @see #addSelectionListener()

 * @see #ensureIndexIsVisible()

var selectionBackground:ASColor

A background color for selected cells.

Cell renderers can use this color to the fill selected cells.

The default value of this property is defined by the look and feel implementation.

@see #selectionForeground @see Component.foreground @see Component.background @see Component.font

var selectionForeground:ASColor

A foreground color for selected cells.

Cell renderers can use this color to render text and graphics for selected cells.

The default value of this property is defined by the look and feel implementation.

@see #selectionBackground @see Component.foreground @see Component.background @see Component.font

var selectionMode:Int

Determines whether single-item or multiple-item selections are allowed. If selection mode changed, will cause clear selection; @see #SINGLESELECTION @see #MULTIPLESELECTION

var selectionModel:ListSelectionModel

A non-null ListSelectionModel implementation.

The selection model handles the task of making single selections, multiple selections.

selectionModel

the ListSelectionModel that implements the selections, if it is null, nothing will be done.

var visibleCellWidth:Int

The preferred width the list that can be displayed.

The default value of this property is -1. -1 means the width that can display all content.

@see #visibleRowCount @see #preferredCellWidthWhenNoCount

var visibleRowCount:Int

The preferred number of rows in the list that can be displayed. -1 means prefer to display all rows.

The default value of this property is -1. The rowHeight will be counted as 20 if the cell factory produces not same height cells. @see #visibleCellWidth()

function new(?listData:Dynamic = null, ?cellFactory:ListCellFactory = null): Void

Create a list.

listData

(optional)a ListModel or a Array.

cellFactory

(optional)the cellFactory for this List.

function addLayoutComponent(comp:Component, constraints:Dynamic): Void

Implementation of LayoutManager interface @see LayoutManager.addLayoutComponent

function addSelectionInterval(index0:Int, index1:Int, ?programmatic:Bool = true): Void

@see ListSelectionModel#addSelectionInterval() @see #removeSelectionInterval()

index0

index0.

index1

index1.

programmatic

indicate if this is a programmatic change.

function addSelectionListener(listener:Dynamic ->Void?priority:Int = 0, ?useWeakReference:Bool = false): Void

Adds a listener to list selection changed. @see org.aswing.event.SelectionEvent

listener

the listener to be add.

priority

the priority

useWeakReference

Determines whether the reference to the listener is strong or weak.

function addStateListener(listener:Dynamic ->Void?priority:Int = 0, ?useWeakReference:Bool = false): Void

Add a listener to listen the viewpoat state change event.

When the viewpoat's state changed, the state is all about:

@see org.aswing.event.InteractiveEvent#STATE_CHANGED

listener

the listener

priority

the priority

useWeakReference

Determines whether the reference to the listener is strong or weak.

function clearSelection(?programmatic:Bool = true): Void

Clears the selection - after calling this method isSelectionEmpty will return true. This is a convenience method that just delegates to the selectionModel.

programmatic

indicate if this is a programmatic change.

function contentsChanged(e:ListDataEvent): Void

Data in the list has changed, update JList if needed.

function ensureIndexIsVisible(index:Int): Void

Scrolls the JList to make the specified cell completely visible. @see #setFirstVisibleIndex()

function getAnchorSelectionIndex(): Int

Returns the first index argument from the most recent addSelectionModel or setSelectionInterval call. This is a convenience method that just delegates to the selectionModel.

@see ListSelectionModel#getAnchorSelectionIndex @see #addSelectionInterval() @see #setSelectionInterval() @see #addSelectionListener()

returns

the index that most recently anchored an interval selection

function getCellByIndex(index:Int): ListCell

Returns the cell of the specified index

function getLayoutAlignmentX(target:Container): Float

Implementation of LayoutManager interface @see LayoutManager.getLayoutAlignmentX

returns

AsWingConstants.CENTER

function getLayoutAlignmentY(target:Container): Float

Implementation of LayoutManager interface @see LayoutManager.getLayoutAlignmentY

returns

0

function getLeadSelectionIndex(): Int

Returns the second index argument from the most recent #addSelectionInterval or #setSelectionInterval call. This is a convenience method that just delegates to the selectionModel.

@see ListSelectionModel#getLeadSelectionIndex @see #addSelectionInterval() @see #setSelectionInterval() @see #addSelectionListener()

returns

the index that most recently ended a interval selection

function getSelectedIndex(): Int

Return the selected index, if selection multiple, return the first. if not selected any, return -1.

returns

the selected index

function getSelectedIndices(): Array<Dynamic>

Returns an array of all of the selected indices in increasing order.

returns

a array contains all selected indices

function getSelectedValue(): Dynamic

Returns the first selected value, or null if the selection is empty.

returns

the first selected value

function getSelectedValues(): Array<Dynamic>

Returns an array of the values for the selected cells. The returned values are sorted in increasing index order.

returns

the selected values or an empty list if nothing is selected

function getViewportPane(): Component

Implementation of Viewportable interface @see Viewportable.getViewportPane

function intervalAdded(e:ListDataEvent): Void

Data in the list has changed, update JList if needed.

function intervalRemoved(e:ListDataEvent): Void

Data in the list has changed, update JList if needed.

function invalidateLayout(target:Container): Void

Implementation of LayoutManager interface @see LayoutManager.invalidateLayout

function isAutoDnDDropTargetAllown(): Bool

Returns is this list allown to automatically be as an drag and drop target. @see #org.aswing.MutableListModel @see #DNDNONE @see #DNDMOVE @see #DND_COPY

function isAutoDnDInitiatorAllown(): Bool

Returns is this list allown to automatically be as an drag and drop initiator. @see #org.aswing.MutableListModel @see #DNDNONE @see #DNDMOVE @see #DND_COPY

function isMutableModel(): Bool

Returns is the source data is acceptale to drop in this list as build-in support

function isSelectedIndex(index:Int): Bool

returns

true if the index is selected, otherwise false.

function isSelectionEmpty(): Bool

Returns true if nothing is selected.

returns

true if nothing is selected, false otherwise.

function layoutContainer(target:Container): Void

Implementation of LayoutManager interface @see LayoutManager.layoutContainer

function maximumLayoutSize(target:Container): IntDimension

Implementation of LayoutManager interface @see LayoutManager.maximumLayoutSize

function minimumLayoutSize(target:Container): IntDimension

Implementation of LayoutManager interface @see LayoutManager.minimumLayoutSize

function preferredLayoutSize(target:Container): IntDimension

Implementation of LayoutManager interface @see LayoutManager.preferredLayoutSize

function removeLayoutComponent(comp:Component): Void

Implementation of LayoutManager interface @see LayoutManager.removeLayoutComponent

function removeSelectionInterval(index0:Int, index1:Int, ?programmatic:Bool = true): Void

@see ListSelectionModel#removeSelectionInterval()

index0

index0.

index1

index1.

programmatic

indicate if this is a programmatic change.

function removeSelectionListener(listener:Dynamic ->Void): Void

Removes a listener from list selection changed listeners. @see org.aswing.event.SelectionEvent

listener

the listener to be removed.

function removeStateListener(listener:Dynamic ->Void): Void

Removes a state listener. @see org.aswing.event.AWEvent#STATE_CHANGED

listener

the listener to be removed.

function scrollToBottomLeft(): Void

Scrolls to view bottom left content. This will make the scrollbars of JScrollPane scrolled automatically, if it is located in a JScrollPane.

function scrollToBottomRight(): Void

Scrolls to view bottom right content. This will make the scrollbars of JScrollPane scrolled automatically, if it is located in a JScrollPane.

function scrollToTopLeft(): Void

Scrolls to view top left content. This will make the scrollbars of JScrollPane scrolled automatically, if it is located in a JScrollPane.

function scrollToTopRight(): Void

Scrolls to view to right content. This will make the scrollbars of JScrollPane scrolled automatically, if it is located in a JScrollPane.

function selectAll(?programmatic:Bool = true): Void

Selects all elements in the list.

* @param programmatic indicate if this is a programmatic change. @see #setSelectionInterval

function setFirstVisibleIndex(index:Int): Void

scroll the list to view the specified index as first visible. If the list data elements is too short can not move the specified index to be first, just scroll as top as can. @see #ensureIndexIsVisible() @see #setLastVisibleIndex()

function setLastVisibleIndex(index:Int): Void

scroll the list to view the specified index as last visible If the list data elements is too short can not move the specified index to be last, just scroll as bottom as can. @see ensureIndexIsVisible() @see setFirstVisibleIndex()

function setSelectedIndex(index:Int, ?programmatic:Bool = true): Void

Selects a single cell. @see ListSelectionModel#setSelectionInterval @see #isSelectedIndex() @see #addSelectionListener()

 * @see #ensureIndexIsVisible()
index

the index to be seleted.

programmatic

indicate if this is a programmatic change.

function setSelectedIndices(indices:Array<Dynamic>, ?programmatic:Bool = true): Void

Selects a set of cells.

This will not cause a scroll, if you want to scroll to visible the selected value, call '#ensureIndexIsVisible'.

@see #isSelectedIndex() @see #addSelectionListener() @see #ensureIndexIsVisible()

indices

an array of the indices of the cells to select.

programmatic

indicate if this is a programmatic change.

function setSelectedValue(value:Dynamic, ?programmatic:Bool = true): Void

Selects the specified object from the list. This will not cause a scroll, if you want to scroll to visible the selected value, call ensureIndexIsVisible(). @param programmatic indicate if this is a programmatic change. @see #setSelectedIndex() @see #ensureIndexIsVisible()

value

the value to be selected. *

function setSelectedValues(values:Array<Dynamic>, ?programmatic:Bool = true): Void

Selects a set of cells.

This will not cause a scroll, if you want to scroll to visible the selected value, call ensureIndexIsVisible(). @see #isSelectedIndex() @see #addSelectionListener() @see #ensureIndexIsVisible()

values

an array of the values to select.

programmatic

indicate if this is a programmatic change.

function setSelectionInterval(index0:Int, index1:Int, ?programmatic:Bool = true): Void

@see ListSelectionModel#setSelectionInterval @see #removeSelectionInterval()

index0

index0.

index1

index1.

programmatic

indicate if this is a programmatic change.

function updateListView(): Void

When your list data changed, and you want to update list view by hand. call this method.

This method is called automatically when setModel called with a different model to set.