charvax.swing

Class JList

Implemented Interfaces:
Scrollable

public class JList
extends JComponent
implements Scrollable

A component that allows the user to select one or more objects from a list.

The JList does not provide scrolling capability. The JList is normally inserted into a JScrollPane to provide scrolling.

Field Summary

protected int
_currentRow
Offset (from start of list) of the item under the cursor (i.e.
protected ListModel
_listModel
The ListModel that holds the items that are displayed by this JList.
protected ListSelectionModel
_selectionModel
The ListSelectionModel used by this JList.

Fields inherited from class charvax.swing.JComponent

_border

Fields inherited from class charva.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT, _alignmentX, _alignmentY, _background, _cursesColor, _enabled, _focusListeners, _foreground, _keyListeners, _origin, _parent, _visible

Constructor Summary

JList()
Constructs a JList with 5 rows, 10 columns wide.
JList(Object[] items_)
Construct a JList containing the items in the specified array.
JList(Vector items_)
Construct a JList containing the items in the specified Vector.
JList(ListModel model_)
Construct a JList that displays the elements in the specified non-null model.

Method Summary

void
addListSelectionListener(ListSelectionListener il_)
Register an ListSelectionListener object for this component.
void
addScrollListener(ScrollListener sl_)
Register a ScrollListener object for this JList.
void
addSelectionInterval(int index0_, int index1_)
Sets the selection to be the set union between the current selection and the specified interval between index0_ and index1_ (inclusive).
void
clearSelection()
Clears the selection.
void
debug(int level_)
Outputs a textual description of this component to stderr.
void
draw()
Draws this component.
void
ensureIndexIsVisible(int index_)
Make the specified item visible (by scrolling the list up or down).
int
getHeight()
int
getMaxSelectionIndex()
Returns the highest selected item index.
int
getMinSelectionIndex()
Returns the lowest selected item index.
ListModel
getModel()
Returns the data model that holds the list of items displayed by this JList.
Dimension
getPreferredScrollableViewportSize()
Returns the size of the viewport needed to display visibleRows rows.
int
getSelectedIndex()
Get the first selected index, or -1 if there is no selected index.
int[]
getSelectedIndices()
Returns an array of the selected indices.
Object
getSelectedValue()
Get the first selected item on this list, or null if the selection is empty.
Object[]
getSelectedValues()
Returns an array of the selected values.
int
getSelectionMode()
Determines whether this list allows multiple selections.
ListSelectionModel
getSelectionModel()
Returns the list's implementation of ListSelectionModel.
Dimension
getSize()
int
getVisibleRowCount()
int
getWidth()
boolean
isIndexSelected(int index_)
Determines if the specified item in this scrolling list is selected.
Dimension
minimumSize()
Called by LayoutManager.
void
processKeyEvent(KeyEvent ke_)
void
processMouseEvent(MouseEvent e_)
void
processScrollEvent(ScrollEvent e_)
Process scroll events generated by this JList.
void
removeListSelectionListener(ListSelectionListener listener_)
Remove the specified ListSelectionListener from the list of listeners that will be notified when the selection changes.
void
removeScrollListener(ScrollListener sl_)
Remove a ScrollListener object that is registered for this JList.
void
removeSelectionInterval(int index0_, int index1_)
Sets the selection to be the set difference between the current selection and the specified interval between index0_ and index1_ (inclusive).
void
requestFocus()
void
setColumns(int cols_)
Set the number of columns INSIDE the list.
void
setListData(Object[] listData_)
Constructs a ListModel from an array of Objects and then applies setModel to it.
void
setListData(Vector listData_)
Constructs a ListModel from a Vector and then applies setModel to it.
void
setModel(ListModel model_)
Sets the model that represents the "contents" of the list, and clears the selection.
void
setSelectedIndex(int index_)
Select the item at the specified index.
void
setSelectionMode(int mode_)
Sets the flag that determines whether this list allows multiple selections.
void
setSelectionModel(ListSelectionModel model_)
Sets the selection model of the JList to an implementation of the ListSelectionModel interface.
void
setVisibleRowCount(int rows_)
Set the maximum number of rows that can be displayed at a time by the JScrollPane which contains this JList.

Methods inherited from class charvax.swing.JComponent

draw, getBorder, getInsets, setBorder

Methods inherited from class charva.awt.Component

addFocusListener, addKeyListener, contains, contains, debug, draw, getAlignmentX, getAlignmentY, getAncestorWindow, getBackground, getBounds, getCursesColor, getForeground, getHeight, getLocation, getLocationOnScreen, getName, getParent, getSize, getWidth, hasFocus, hide, invalidate, isDisplayed, isEnabled, isFocusTraversable, isTotallyObscured, isValid, isVisible, minimumSize, processEvent, processFocusEvent, processKeyEvent, processMouseEvent, repaint, requestFocus, requestSync, setBackground, setEnabled, setForeground, setLocation, setLocation, setName, setParent, setVisible, show, validate, validateCursesColor

Field Details

_currentRow

protected int _currentRow
Offset (from start of list) of the item under the cursor (i.e. the item that will be selected/deselected if the user presses ENTER)

_listModel

protected ListModel _listModel
The ListModel that holds the items that are displayed by this JList.

_selectionModel

protected ListSelectionModel _selectionModel
The ListSelectionModel used by this JList.

Constructor Details

JList

public JList()
Constructs a JList with 5 rows, 10 columns wide.

JList

public JList(Object[] items_)
Construct a JList containing the items in the specified array.

JList

public JList(Vector items_)
Construct a JList containing the items in the specified Vector.

JList

public JList(ListModel model_)
Construct a JList that displays the elements in the specified non-null model.

Method Details

addListSelectionListener

public void addListSelectionListener(ListSelectionListener il_)
Register an ListSelectionListener object for this component. The listener is notified each time a change to the selection occurs.

addScrollListener

public void addScrollListener(ScrollListener sl_)
Register a ScrollListener object for this JList.
Specified by:
addScrollListener in interface Scrollable

addSelectionInterval

public void addSelectionInterval(int index0_,
                                 int index1_)
Sets the selection to be the set union between the current selection and the specified interval between index0_ and index1_ (inclusive).

clearSelection

public void clearSelection()
Clears the selection. After this isSelectionEmpty() will return true.

debug

public void debug(int level_)
Outputs a textual description of this component to stderr.
Overrides:
debug in interface Component

draw

public void draw()
Draws this component. Overrides draw() in Component.
Overrides:
draw in interface JComponent

ensureIndexIsVisible

public void ensureIndexIsVisible(int index_)
Make the specified item visible (by scrolling the list up or down). This method does not do anything unless the JList is in a JViewport. Note that the list is not redrawn by this method; the redrawing is done by the JScrollPane (that is registered as a ScrollListener).

getHeight

public int getHeight()
Overrides:
getHeight in interface Component

getMaxSelectionIndex

public int getMaxSelectionIndex()
Returns the highest selected item index.

getMinSelectionIndex

public int getMinSelectionIndex()
Returns the lowest selected item index.

getModel

public ListModel getModel()
Returns the data model that holds the list of items displayed by this JList.

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns the size of the viewport needed to display visibleRows rows.
Specified by:
getPreferredScrollableViewportSize in interface Scrollable

getSelectedIndex

public int getSelectedIndex()
Get the first selected index, or -1 if there is no selected index.

getSelectedIndices

public int[] getSelectedIndices()
Returns an array of the selected indices. The indices are sorted in increasing index order.

getSelectedValue

public Object getSelectedValue()
Get the first selected item on this list, or null if the selection is empty.

getSelectedValues

public Object[] getSelectedValues()
Returns an array of the selected values. The objects are sorted in increasing index order.

getSelectionMode

public int getSelectionMode()
Determines whether this list allows multiple selections.

getSelectionModel

public ListSelectionModel getSelectionModel()
Returns the list's implementation of ListSelectionModel.

getSize

public Dimension getSize()
Overrides:
getSize in interface Component

getVisibleRowCount

public int getVisibleRowCount()

getWidth

public int getWidth()
Overrides:
getWidth in interface Component

isIndexSelected

public boolean isIndexSelected(int index_)
Determines if the specified item in this scrolling list is selected.

minimumSize

public Dimension minimumSize()
Called by LayoutManager.
Overrides:
minimumSize in interface Component

processKeyEvent

public void processKeyEvent(KeyEvent ke_)
Overrides:
processKeyEvent in interface Component

processMouseEvent

public void processMouseEvent(MouseEvent e_)
Overrides:
processMouseEvent in interface Component

processScrollEvent

public void processScrollEvent(ScrollEvent e_)
Process scroll events generated by this JList.
Specified by:
processScrollEvent in interface Scrollable

removeListSelectionListener

public void removeListSelectionListener(ListSelectionListener listener_)
Remove the specified ListSelectionListener from the list of listeners that will be notified when the selection changes.

removeScrollListener

public void removeScrollListener(ScrollListener sl_)
Remove a ScrollListener object that is registered for this JList.
Specified by:
removeScrollListener in interface Scrollable

removeSelectionInterval

public void removeSelectionInterval(int index0_,
                                    int index1_)
Sets the selection to be the set difference between the current selection and the specified interval between index0_ and index1_ (inclusive).

requestFocus

public void requestFocus()
Overrides:
requestFocus in interface Component

setColumns

public void setColumns(int cols_)
Set the number of columns INSIDE the list.

setListData

public void setListData(Object[] listData_)
Constructs a ListModel from an array of Objects and then applies setModel to it.

setListData

public void setListData(Vector listData_)
Constructs a ListModel from a Vector and then applies setModel to it.

setModel

public void setModel(ListModel model_)
Sets the model that represents the "contents" of the list, and clears the selection.

setSelectedIndex

public void setSelectedIndex(int index_)
Select the item at the specified index. Note that this method does not redraw the JList.

setSelectionMode

public void setSelectionMode(int mode_)
Sets the flag that determines whether this list allows multiple selections.
Parameters:
mode_ - the selection mode. Allowed values are:

  • ListSelectionModel.SINGLE_SELECTION. Only one list index can be selected at a time.
  • ListSelectionModel.SINGLE_INTERVAL_SELECTION.
  • ListSelectionModel.MULTIPLE_INTERVAL_SELECTION. Any number of list items can be selected simultaneously.

setSelectionModel

public void setSelectionModel(ListSelectionModel model_)
Sets the selection model of the JList to an implementation of the ListSelectionModel interface.

setVisibleRowCount

public void setVisibleRowCount(int rows_)
Set the maximum number of rows that can be displayed at a time by the JScrollPane which contains this JList.