public class IlxWList extends IlxWComponent
The IlxWList data model is an instance of javax.swing.ListModel.
Its selection state is managed by an instance of
javax.swing.ListSelectionModel.
By default, the IlxWList is rendered on the browser as a
<select> HTML element. Its cells are rendered as
<option> elements whose values are the result of the
toString() method performed on the cell data.
However, you may provide a custom cell renderer through the
setCellRenderer method. You may either subclass the default
cell renderer (IlxWDefaultListCellRenderer) or implement
the IlxWListCellRenderer interface.
The default cell renderer uses an IlxWLabel component to
render the string value of each component. You can substitute your
own cell renderer, using code like this:
// Display an icon and a string for each object in the list. class MyCellRenderer extends IlxWLabel implements IlxWListCellRenderer { public IlxWComponent getListCellRendererComponent( IlxWList list, Object value, int index, boolean isSelected) { setText(value.toString()); if (isSelected) { getStyle().set("backgroundColor", "red"); getStyle().set("color", "white"); } else { getStyle().set("backgroundColor", "white"); getStyle().set("color", "black"); } return this; } } String[] data = {"one", "two", "three", "four"}; IlxWList dataList = new IlxWList(data); dataList.setCellRenderer(new MyCellRenderer());
,
IlxWListCellRenderer,
IlxWDefaultListCellRenderer,
Serialized Form
IlxWComponent.DynamicStyleMap| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACTION_PROPERTY
Name of the action property.
|
static java.lang.String |
CELL_RENDERER_PROPERTY
Name of the cellRenderer property.
|
static java.lang.String |
CSS_RESOURCE_NAME
Resource path to the user-agent CSS.
|
static java.lang.String |
MODEL_PROPERTY
Name of the model property.
|
static java.lang.String |
SELECTION_MODEL_PROPERTY
Name of the selectionModel property.
|
static java.lang.String |
UI_PROPERTY
Name of the UI property.
|
listenerList| Constructor and Description |
|---|
IlxWList()
Constructs an
IlxWList with an empty model. |
IlxWList(javax.swing.ListModel model)
Constructs an
IlxWList that displays the elements in the
specified, non-null model. |
IlxWList(java.lang.Object[] listData)
Constructs an
IlxWList that displays the elements in the
specified array. |
| Modifier and Type | Method and Description |
|---|---|
void |
addListSelectionListener(javax.swing.event.ListSelectionListener listener)
Adds a listener to the list that's notified each time a change
to the selection occurs.
|
void |
addSelectionInterval(int anchor,
int lead)
Sets the selection to be the union of the specified interval with current
selection.
|
void |
clearSelection()
Clears the selection - after calling this method
isSelectionEmpty will return true. |
protected javax.swing.ListSelectionModel |
createSelectionModel()
Returns an instance of
DefaultListSelectionModel. |
protected void |
fireSelectionValueChanged(int firstIndex,
int lastIndex,
boolean isAdjusting)
Notifies
IlxWList ListSelectionListeners that
the selection model has changed. |
IlxWAction |
getAction()
Gets the action that will be called when the user selects an item
in the list.
|
int |
getAnchorSelectionIndex()
Returns the first index argument from the most recent
addSelectionModel or setSelectionInterval call. |
IlxWComponent |
getCellAt(int index)
Gets the component representing the cell at the given index.
|
IlxWListCellRenderer |
getCellRenderer()
Returns the object that renders the list items.
|
int |
getColumnWidth()
Returns the width of the component in pixels.
|
int |
getLeadSelectionIndex()
Returns the second index argument from the most recent
addSelectionInterval or setSelectionInterval
call. |
javax.swing.event.ListSelectionListener[] |
getListSelectionListeners() |
int |
getMaxSelectionIndex()
Returns the largest selected cell index.
|
int |
getMinSelectionIndex()
Returns the smallest selected cell index.
|
javax.swing.ListModel |
getModel()
Returns the data model that holds the list of items displayed
by the
IlxWList component. |
int |
getRowHeight()
Returns the height of the component.
|
int |
getSelectedIndex()
Returns the first selected index.
|
java.lang.Object |
getSelectedValue()
Returns the first selected value, or
null if the
selection is empty. |
int |
getSelectionMode()
Returns whether single-item or multiple-item selections are allowed.
|
javax.swing.ListSelectionModel |
getSelectionModel()
Returns the value of the current selection model.
|
protected IlxWCSSRuleset |
getUserAgentRules()
Gets the "user-agent" CSS rules.
|
boolean |
isEnabled()
Determines whether this component is enabled.
|
boolean |
isSelectedIndex(int index)
Returns true if the specified index is selected.
|
boolean |
isSelectionEmpty()
Returns true if nothing is selected.
|
void |
notifyDependencies(IlxWPort port) |
protected void |
printComponent(IlxWPort port)
Prints the HTML code that will display the graphical
representation of this component.
|
void |
removeListSelectionListener(javax.swing.event.ListSelectionListener listener)
Removes a listener from the list that is notified each time a
change to the selection occurs.
|
void |
removeSelectionInterval(int index0,
int index1)
Sets the selection to be the set difference of the specified interval
and the current selection.
|
void |
setAction(IlxWAction action)
Sets the action which will be called when the user selects an item
in the list.
|
void |
setCellRenderer(IlxWListCellRenderer cellRenderer)
Sets the delegate used to render each cell in the list.
|
void |
setColumnWidth(int columnWidth)
Sets the width of the component in pixels.
|
void |
setEnabled(boolean enabled)
Enables or disables this component.
|
void |
setListData(java.lang.Object[] listData)
Constructs a
ListModel from an array of objects and then
applies setModel to it. |
void |
setModel(javax.swing.ListModel model)
Sets the model that represents the contents or "value" of the
list and clears the list selection after notifying
PropertyChangeListeners. |
void |
setRowHeight(int rowHeight)
Sets the height of the component, that is, the number
of items displayed in the drop-down list without scrolling.
|
void |
setSelectedIndex(int index)
Selects a single cell.
|
void |
setSelectedValue(java.lang.Object element)
Selects the specified object from the list.
|
void |
setSelectionInterval(int anchor,
int lead)
Selects the specified interval.
|
void |
setSelectionMode(int selectionMode)
Determines whether single-item or multiple-item
selections are allowed.
|
void |
setSelectionModel(javax.swing.ListSelectionModel selectionModel)
Sets the
selectionModel for the list to a
non-null ListSelectionModel
implementation. |
addPropertyChangeListener, addPropertyChangeListener, detach, doPrint, firePropertyChange, firePropertyChange, getName, getRealHtmlTagName, getStyle, invalidate, isInvalidated, print, removePropertyChangeListener, removePropertyChangeListener, setName, validateadd, add, getAttribute, getAttributeNames, getComponent, getComponentCount, getComponentNamed, getComponents, getManager, getParent, indexOf, isAncestorOf, remove, remove, removeAll, removeAttribute, setAttribute, setAuthorRules, setFinalizerpublic static final java.lang.String MODEL_PROPERTY
public static final java.lang.String SELECTION_MODEL_PROPERTY
public static final java.lang.String CELL_RENDERER_PROPERTY
public static final java.lang.String ACTION_PROPERTY
public static final java.lang.String UI_PROPERTY
public static final java.lang.String CSS_RESOURCE_NAME
public IlxWList(javax.swing.ListModel model)
IlxWList that displays the elements in the
specified, non-null model.
All IlxWList constructors delegate to this one.
java.lang.IllegalArgumentException - If dataModel
is nullmodel - The data model for this list.public IlxWList(java.lang.Object[] listData)
IlxWList that displays the elements in the
specified array.
This constructor simply delegates to the
ListModel constructor.
listData - The array of Objects to be loaded into the data model.public IlxWList()
IlxWList with an empty model.public int getColumnWidth()
public void setColumnWidth(int columnWidth)
columnWidth - The width of the component in pixels.public int getRowHeight()
public void setRowHeight(int rowHeight)
rowHeight - The height of the component in list items.public IlxWListCellRenderer getCellRenderer()
IlxWListCellRenderer.setCellRenderer(ilog.webui.dhtml.components.IlxWListCellRenderer)public void setCellRenderer(IlxWListCellRenderer cellRenderer)
By default this property is null and the list
is rendered as a <select> HTML element where cells are
representing by an <option> element whose values are the string
values of the data model.
To see an example which sets the cell renderer,
see the class description above.
cellRenderer - The IlxWListCellRenderer
that renders list cells.getCellRenderer()public javax.swing.ListModel getModel()
IlxWList component.setModel(javax.swing.ListModel)public void setModel(javax.swing.ListModel model)
PropertyChangeListeners.java.lang.IllegalArgumentException - If model is
null.model - The ListModel that provides the
list of items for display.getModel()public void setListData(java.lang.Object[] listData)
ListModel from an array of objects and then
applies setModel to it.listData - An array of Objects containing the items to display
in the list.setModel(javax.swing.ListModel)protected javax.swing.ListSelectionModel createSelectionModel()
DefaultListSelectionModel.
This method is used by the constructor to initialize the
selectionModel property.
ListSelectionModel used by this list.setSelectionModel(javax.swing.ListSelectionModel),
DefaultListSelectionModelpublic javax.swing.ListSelectionModel getSelectionModel()
The selection model handles the task of making single selections, selections of contiguous ranges, and non-contiguous selections.
setSelectionModel(javax.swing.ListSelectionModel),
ListSelectionModelprotected void fireSelectionValueChanged(int firstIndex,
int lastIndex,
boolean isAdjusting)
IlxWList ListSelectionListeners that
the selection model has changed.
It is used to forward
ListSelectionEvents from the selectionModel
to the ListSelectionListeners added directly to the
IlxWList.
firstIndex - The first selected index.lastIndex - The last selected index.isAdjusting - True if multiple changes are being made.addListSelectionListener(javax.swing.event.ListSelectionListener),
removeListSelectionListener(javax.swing.event.ListSelectionListener)public javax.swing.event.ListSelectionListener[] getListSelectionListeners()
public void addListSelectionListener(javax.swing.event.ListSelectionListener listener)
Listeners added directly to the IlxWList
will have their ListSelectionEvent.getSource() ==
this IlxWList
(instead of the ListSelectionModel).
listener - The ListSelectionListener to add.getSelectionModel()public void removeListSelectionListener(javax.swing.event.ListSelectionListener listener)
listener - The ListSelectionListener to remove.addListSelectionListener(javax.swing.event.ListSelectionListener),
getSelectionModel()public void setSelectionModel(javax.swing.ListSelectionModel selectionModel)
selectionModel for the list to a
non-null ListSelectionModel
implementation.
The selection model handles the task of making single selections, selections of contiguous ranges, and non-contiguous selections.
java.lang.IllegalArgumentException - If selectionModel
is null.selectionModel - The ListSelectionModel that
implements the selections.getSelectionModel()public void setSelectionMode(int selectionMode)
The following selectionMode values are allowed:
SINGLE_SELECTION
Only one list index can be selected at a time. In this
mode the setSelectionInterval and
addSelectionInterval
methods are equivalent, and only the second index
argument is used.SINGLE_INTERVAL_SELECTION
One contiguous index interval can be selected at a time.
In this mode setSelectionInterval and
addSelectionInterval
are equivalent.MULTIPLE_INTERVAL_SELECTION
In this mode, there is no restriction as to what can be selected.
This is the default value.selectionMode - An integer specifying the type of selections
that are permissible.getSelectionMode()public int getSelectionMode()
setSelectionMode(int)public int getAnchorSelectionIndex()
addSelectionModel or setSelectionInterval call.
This is a convenience method that just delegates to the
selectionModel.
ListSelectionModel.getAnchorSelectionIndex(),
addSelectionInterval(int, int),
setSelectionInterval(int, int),
addListSelectionListener(javax.swing.event.ListSelectionListener)public int getLeadSelectionIndex()
addSelectionInterval or setSelectionInterval
call.
This is a convenience method that just delegates to the
selectionModel.
ListSelectionModel.getLeadSelectionIndex(),
addSelectionInterval(int, int),
setSelectionInterval(int, int),
addListSelectionListener(javax.swing.event.ListSelectionListener)public int getMinSelectionIndex()
This is a convenience method that just delegates to the
selectionModel.
ListSelectionModel.getMinSelectionIndex(),
addListSelectionListener(javax.swing.event.ListSelectionListener)public int getMaxSelectionIndex()
This is a convenience method that just delegates to the
selectionModel.
ListSelectionModel.getMaxSelectionIndex(),
addListSelectionListener(javax.swing.event.ListSelectionListener)public boolean isSelectedIndex(int index)
This is a convenience method that just delegates to the
selectionModel.
index - Index to be queried for selection state.ListSelectionModel.isSelectedIndex(int),
setSelectedIndex(int),
addListSelectionListener(javax.swing.event.ListSelectionListener)public boolean isSelectionEmpty()
This is a convenience method that just delegates to the
selectionModel.
true if nothing is selected.ListSelectionModel.isSelectionEmpty(),
clearSelection(),
addListSelectionListener(javax.swing.event.ListSelectionListener)public void clearSelection()
isSelectionEmpty will return true.
This is a convenience method that just delegates to the
selectionModel.
ListSelectionModel.clearSelection(),
isSelectionEmpty(),
addListSelectionListener(javax.swing.event.ListSelectionListener)public void setSelectionInterval(int anchor,
int lead)
It is not necessary for anchor to be less than lead.
This is a convenience method that just delegates to the
selectionModel.
anchor - The first index to select.lead - The last index to select.ListSelectionModel.setSelectionInterval(int, int),
addSelectionInterval(int, int),
removeSelectionInterval(int, int),
addListSelectionListener(javax.swing.event.ListSelectionListener)public void addSelectionInterval(int anchor,
int lead)
Both the anchor and lead indices are
included. It is not necessary for anchor to be less than lead.
This is a convenience method that just delegates to the
selectionModel.
anchor - The first index to add to the selection.lead - The last index to add to the selection.ListSelectionModel.addSelectionInterval(int, int),
setSelectionInterval(int, int),
removeSelectionInterval(int, int),
addListSelectionListener(javax.swing.event.ListSelectionListener)public void removeSelectionInterval(int index0,
int index1)
Both the anchor and lead indices are
removed. It is not necessary for anchor to be less than lead.
This is a convenience method that just delegates to the
selectionModel.
index0 - The first index to remove from the selection.index1 - The last index to remove from the selection.ListSelectionModel.removeSelectionInterval(int, int),
setSelectionInterval(int, int),
addSelectionInterval(int, int),
addListSelectionListener(javax.swing.event.ListSelectionListener)public void setSelectedIndex(int index)
index - The index of the one cell to select.ListSelectionModel.setSelectionInterval(int, int),
isSelectedIndex(int),
addListSelectionListener(javax.swing.event.ListSelectionListener)public int getSelectedIndex()
Returns -1 if there is no selected item.
getMinSelectionIndex.getMinSelectionIndex(),
addListSelectionListener(javax.swing.event.ListSelectionListener)public java.lang.Object getSelectedValue()
null if the
selection is empty.getMinSelectionIndex(),
getModel(),
addListSelectionListener(javax.swing.event.ListSelectionListener)public void setSelectedValue(java.lang.Object element)
The list will scroll to display the selected object.
element - The object to select.public boolean isEnabled()
true if the component is enabled; false
otherwise.setEnabled(boolean)public void setEnabled(boolean enabled)
enabled - If true, this component is enabled; otherwise this
component is disabled.isEnabled()public IlxWAction getAction()
By default, this action is a Java action (IlxWJavaAction)
of which the perform method calls
setSelectedIndex on the list.
If the given action is a Java action (IlxWJavaAction),
or a JavaScript action (IlxWJSAction),
the argument array passed to the perform
method is a 1-length array containing the string representation
of the selected index.
setAction(ilog.webui.dhtml.components.IlxWAction)public void setAction(IlxWAction action)
action - The action to perform when the user selects an item from the
list.getAction()protected IlxWCSSRuleset getUserAgentRules()
IlxWContainersetAuthorRules method.
This method returns null by default but is intended
to be redefined by subclasses.
getUserAgentRules in class IlxWContainerIlxWContainer.setAuthorRules(ilog.webui.dhtml.IlxWCSSRuleset)protected void printComponent(IlxWPort port) throws java.io.IOException
IlxWComponentIlxWComponent.print(ilog.webui.dhtml.IlxWPort) method.printComponent in class IlxWComponentjava.io.IOExceptionport - The port on which the component will be printed.IlxWComponent.print(ilog.webui.dhtml.IlxWPort)public IlxWComponent getCellAt(int index)
IlxWListCellRenderer.getListCellComponent.
Under certain circumstances you may actually need to access the cell component, in order, for instance, to dynamically set the background-color of the whole cell.
This component is not persistent and can be deleted/created at any
time during the rendering phase. Consequently you should call this
method only from the scope of
IlxWListCellRenderer.getListCellComponent, and
never keep a reference on the returned component outside this scope.
public void notifyDependencies(IlxWPort port)
notifyDependencies in interface ilog.webui.dhtml.IlxWDependencyProvidernotifyDependencies in class IlxWComponent© Copyright IBM Corp. 1987, 2017