Class org.aswing.JList

Implemented Interfaces

Viewportable LayoutManager ListDataListener

Description

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

Field Index

MULTIPLE_SELECTION, ON_ITEM_CLICKED, ON_ITEM_PRESS, ON_ITEM_RELEASE, ON_ITEM_RELEASEOUTSIDE, ON_ITEM_ROLLOUT, ON_ITEM_ROLLOVER, ON_LIST_SCROLL, ON_SELECTION_CHANGE, ON_STATE_CHANGED, SINGLE_SELECTION

Inherited from Container

Inherited from Component

Inherited from EventDispatcher

Method Index

new JList()
addChangeListener(), addLayoutComponent(), addSelectionListener(), clearSelection(), contentsChanged(), ensureIndexIsVisible(), getCellFactory(), getExtentSize(), getFirstVisibleIndex(), getHorizontalBlockIncrement(), getHorizontalUnitIncrement(), getLastVisibleIndex(), getLayoutAlignmentX(), getLayoutAlignmentY(), getModel(), getPreferredWidthWhenNoCount(), getSelectedIndex(), getSelectedIndices(), getSelectedValue(), getSelectedValues(), getSelectionMode(), getUIClassID(), getVerticalBlockIncrement(), getVerticalUnitIncrement(), getViewportPane(), getViewPosition(), getViewSize(), getVisibleRowCount(), intervalAdded(), intervalRemoved(), invalidateLayout(), isSelectedIndex(), isSelectionEmpty(), layoutContainer(), maximumLayoutSize(), minimumLayoutSize(), preferredLayoutSize(), removeLayoutComponent(), scrollRectToVisible(), scrollToBottomLeft(), scrollToBottomRight(), scrollToTopLeft(), scrollToTopRight(), setCellFactory(), setEnabled(), setFirstVisibleIndex(), setLastVisibleIndex(), setLayout(), setListData(), setModel(), setPreferredWidthWhenNoCount(), setSelectedIndex(), setSelectedIndices(), setSelectedValue(), setSelectionMode(), setUI(), setViewportTestSize(), setViewPosition(), updateListView(), updateUI()

Inherited from Container

Inherited from Component

Inherited from EventDispatcher

Constructor Detail

JList

public function JList(listData:Object, cellFactory:ListCellFactory)

JList(listData:Array, cellFactory:ListCellFactory)
JList(model:ListModel, cellFactory:ListCellFactory)
JList(listData:Array)
JList(model:ListModel)
JList()

Parameters

listDataa ListModel or a Array.
cellFactorythe cellFactory for this List.

Field Detail

ON_STATE_CHANGED

static public ON_STATE_CHANGED:String
When the JList Viewportable state changed.
onStateChanged Event{source:JList}

ON_SELECTION_CHANGE

static public ON_SELECTION_CHANGE:String
When the list selection changed.
onSelectionChange Event{source:JList}

ON_LIST_SCROLL

static public ON_LIST_SCROLL:String
onListScroll Event{source:JList}

ON_ITEM_PRESS

static public ON_ITEM_PRESS:String
onItemPress Event{source:JList, value:Object, cell:ListCell}

ON_ITEM_RELEASE

static public ON_ITEM_RELEASE:String
onItemRelease Event{source:JList, value:Object, cell:ListCell}

ON_ITEM_RELEASEOUTSIDE

static public ON_ITEM_RELEASEOUTSIDE:String
onItemReleaseOutSide Event{source:JList, value:Object, cell:ListCell}

ON_ITEM_ROLLOVER

static public ON_ITEM_ROLLOVER:String
onItemRollOver Event{source:JList, value:Object, cell:ListCell}

ON_ITEM_ROLLOUT

static public ON_ITEM_ROLLOUT:String
onItemRollOut Event{source:JList, value:Object, cell:ListCell}

ON_ITEM_CLICKED

static public ON_ITEM_CLICKED:String
onItemClicked Event{source:JList, value:Object, cell:ListCell, clickCount:Number}

SINGLE_SELECTION

static public SINGLE_SELECTION:Number
Only can select one most item at a time.

MULTIPLE_SELECTION

static public MULTIPLE_SELECTION:Number
Can select any item at a time.

Method Detail

updateUI

public function updateUI():Void

Description copied from Component

Resets the UI property to a value from the current look and feel. Component subclasses must override this method like this:

   public void updateUI() {
      setUI((SliderUI)UIManager.getUI(this);
   }
  

Overrides

updateUI() in org.aswing.Component

setUI

public function setUI(newUI:ListUI):Void

Description copied from Component

Sets the look and feel delegate for this component. Component subclasses generally override this method to narrow the argument type. For example, in JSlider:

 public void setUI(SliderUI newUI) {
     super.setUI(newUI);
 }
  

Additionally Component subclasses must provide a getUI method that returns the correct type. For example:

 public SliderUI getUI() {
     return (SliderUI)ui;
 }
 

Overrides

setUI() in org.aswing.Component

getUIClassID

public function getUIClassID():String

Description copied from Component

Returns the UIDefaults key used to look up the name of the org.aswing.plaf.ComponentUI class that defines the look and feel for this component. Most applications will never need to call this method. Subclasses of Component that support pluggable look and feel should override this method to return a UIDefaults key that maps to the ComponentUI subclass that defines their look and feel.

Overrides

getUIClassID() in org.aswing.Component

setLayout

public function setLayout(layout:LayoutManager):Void

Can not set layout to JList, its layout is itself.

Throws

Errorwhen set any layout.

Overrides

setLayout() in org.aswing.Container

setListData

public function setListData(ld:Array):Void

set a array to be the list data, but array is not a List Mode. So when the array content was changed, you should call updateListView to update the JList.But this is not a good way, its slow. So suggest you to create a ListMode ex VectorListMode to JList, When you modify ListMode, it will automatic update JList.

See Also

setModel

public function setModel(m:ListModel):Void

Set the list mode to provide the data to JList.

See Also

getModel

public function getModel():ListModel

Return

the model of this List

getCellFactory

public function getCellFactory():ListCellFactory

Return

the cellFactory of this List

setCellFactory

public function setCellFactory(newFactory:ListCellFactory):Void

This will cause all cells recreating by new factory.

Parameters

newFactorythe new cell factory for this List

addSelectionListener

public function addSelectionListener(func:Function, obj:Object):Object

Add listener to selection changed.

See Also

getPreferredWidthWhenNoCount

public function getPreferredWidthWhenNoCount():Number

Return

the default preferred with of the List when shareCelles.

See Also

setPreferredWidthWhenNoCount

public function setPreferredWidthWhenNoCount(preferredWidthWhenNoCount:Number):Void

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

When ListCellFactory is shareCelles, List will not count prefferred width.

Parameters

preferredWidthWhenNoCountthe preferred with of the List.

updateListView

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

clearSelection

public function clearSelection():Void

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

setSelectionMode

public function setSelectionMode(sm:Number):Void

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

See Also

getSelectionMode

public function getSelectionMode():Number

Return whether single-item or multiple-item selections are allowed.

See Also

getSelectedIndex

public function getSelectedIndex():Number

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

Return

the selected index

isSelectionEmpty

public function isSelectionEmpty():Boolean

Returns true if nothing is selected.

Return

true if nothing is selected, false otherwise.

getSelectedIndices

public function getSelectedIndices():Array

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

Return

a array contains all selected indices

isSelectedIndex

public function isSelectedIndex(index:Number):Boolean

Return

true if the index is selected, otherwise false.

getSelectedValue

public function getSelectedValue():Object

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

Return

the first selected value

getSelectedValues

public function getSelectedValues():Array

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

Return

the selected values or an empty list if nothing is selected

setSelectedIndex

public function setSelectedIndex(index:Number):Void

Selects a single cell. This will cause ON_SELECTION_CHANGE event only if the new index is different from currently selection.

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

Parameters

indexthe index of the one cell to select

See Also

setSelectedIndices

public function setSelectedIndices(indices:Array):Void

Selects a set of cells. This will cause ON_SELECTION_CHANGE event what ever the new indices is different from current selection or not. If new the selection mode is SINGAL_SELECTION mode, just set the first index in indices.

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

Parameters

indicesan array of the indices of the cells to select

See Also

setSelectedValue

public function setSelectedValue(value:Object):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().

See Also

ensureIndexIsVisible

public function ensureIndexIsVisible(index:Number):Void

Scrolls the JList to make the specified cell completely visible.

See Also

  • setFirstVisibleIndex()

getFirstVisibleIndex

public function getFirstVisibleIndex():Number

setFirstVisibleIndex

public function setFirstVisibleIndex(index:Number):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 Also

  • ensureIndexIsVisible()
  • setLastVisibleIndex()

getLastVisibleIndex

public function getLastVisibleIndex():Number

setLastVisibleIndex

public function setLastVisibleIndex(index:Number):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 Also

  • ensureIndexIsVisible()
  • setFirstVisibleIndex()

getVisibleRowCount

public function getVisibleRowCount():Number

Return currently visible cells count.

scrollToBottomLeft

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

scrollToBottomRight

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

scrollToTopLeft

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

scrollToTopRight

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

setEnabled

public function setEnabled(b:Boolean):Void

Enables the list so that items can be selected.

getVerticalUnitIncrement

public function getVerticalUnitIncrement():Number

Description copied from Viewportable

Returns the unit value for the Vertical scrolling.

Specified By

getVerticalUnitIncrement() in org.aswing.Viewportable

getVerticalBlockIncrement

public function getVerticalBlockIncrement():Number

Description copied from Viewportable

Return the block value for the Vertical scrolling.

Specified By

getVerticalBlockIncrement() in org.aswing.Viewportable

getHorizontalUnitIncrement

public function getHorizontalUnitIncrement():Number

Description copied from Viewportable

Returns the unit value for the Horizontal scrolling.

Specified By

getHorizontalUnitIncrement() in org.aswing.Viewportable

getHorizontalBlockIncrement

public function getHorizontalBlockIncrement():Number

Description copied from Viewportable

Return the block value for the Horizontal scrolling.

Specified By

getHorizontalBlockIncrement() in org.aswing.Viewportable

setViewportTestSize

public function setViewportTestSize(s:Dimension):Void

Description copied from Viewportable

Before JScrollPane analyse the scroll properties(call getExtentSize and getViewSize), it will call this method to set the size of viewport will be to test.

Specified By

setViewportTestSize() in org.aswing.Viewportable

getExtentSize

public function getExtentSize():Dimension

Description copied from Viewportable

Returns the size of the visible part of the view in view logic coordinates.

Specified By

getExtentSize() in org.aswing.Viewportable

getViewSize

public function getViewSize():Dimension

Description copied from Viewportable

Returns the viewportable view's amount size if view all content in view logic coordinates. Usually the view's preffered size.

Specified By

getViewSize() in org.aswing.Viewportable

getViewPosition

public function getViewPosition():Point

Description copied from Viewportable

Returns the view coordinates that appear in the upper left hand corner of the viewport, or 0,0 if there's no view. in view logic coordinates.

Specified By

getViewPosition() in org.aswing.Viewportable

setViewPosition

public function setViewPosition(p:Point):Void

Description copied from Viewportable

Sets the view coordinates that appear in the upper left hand corner of the viewport. in view logic coordinates.

Specified By

setViewPosition() in org.aswing.Viewportable

scrollRectToVisible

public function scrollRectToVisible(contentRect:Rectangle):Void

Description copied from Viewportable

Scrolls the view so that Rectangle within the view becomes visible. in view logic coordinates.

Note that this method will not scroll outside of the valid viewport; for example, if contentRect is larger than the viewport, scrolling will be confined to the viewport's bounds.

Specified By

scrollRectToVisible() in org.aswing.Viewportable

addChangeListener

public function addChangeListener(func:Function, obj:Object):Object

Description copied from Viewportable

Add a listener to listen the viewpoat state change event.

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

  • viewPosition

onStateChanged Event{source:Viewportable}

Specified By

addChangeListener() in org.aswing.Viewportable

getViewportPane

public function getViewportPane():Component

Description copied from Viewportable

Return the component of the viewportable's pane which would added to displayed on the stage.

Specified By

getViewportPane() in org.aswing.Viewportable

addLayoutComponent

public function addLayoutComponent(comp:Component, constraints:Object):Void

removeLayoutComponent

public function removeLayoutComponent(comp:Component):Void

preferredLayoutSize

public function preferredLayoutSize(target:Container):Dimension

Description copied from LayoutManager

Calculates the preferred size dimensions for the specified container, given the components it contains.

Specified By

preferredLayoutSize() in org.aswing.LayoutManager

minimumLayoutSize

public function minimumLayoutSize(target:Container):Dimension

Description copied from LayoutManager

Calculates the minimum size dimensions for the specified container, given the components it contains.

Specified By

minimumLayoutSize() in org.aswing.LayoutManager

maximumLayoutSize

public function maximumLayoutSize(target:Container):Dimension

Description copied from LayoutManager

Calculates the maximum size dimensions for the specified container, given the components it contains.

Specified By

maximumLayoutSize() in org.aswing.LayoutManager

layoutContainer

public function layoutContainer(target:Container):Void

position and fill cells here

Specified By

layoutContainer() in org.aswing.LayoutManager

getLayoutAlignmentX

public function getLayoutAlignmentX(target:Container):Number

getLayoutAlignmentY

public function getLayoutAlignmentY(target:Container):Number

invalidateLayout

public function invalidateLayout(target:Container):Void

Description copied from LayoutManager

Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Specified By

invalidateLayout() in org.aswing.LayoutManager

intervalAdded

public function intervalAdded(e:ListDataEvent):Void

data in list has changed, update JList if needed.

Specified By

intervalAdded() in org.aswing.events.ListDataListener

intervalRemoved

public function intervalRemoved(e:ListDataEvent):Void

data in list has changed, update JList if needed.

Specified By

intervalRemoved() in org.aswing.events.ListDataListener

contentsChanged

public function contentsChanged(e:ListDataEvent):Void

data in list has changed, update JList if needed.

Specified By

contentsChanged() in org.aswing.events.ListDataListener