charvax.swing
Class JList

java.lang.Object
  extended bycharva.awt.Component
      extended bycharvax.swing.JComponent
          extended bycharvax.swing.JList
All 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
_alignmentX, _alignmentY, _background, _cursesColor, _enabled, _focusListeners, _foreground, _keyListeners, _origin, _parent, _visible, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
JList()
          Constructs a JList with 5 rows, 10 columns wide.
JList(ListModel model_)
          Construct a JList that displays the elements in the specified non-null model.
JList(java.lang.Object[] items_)
          Construct a JList containing the items in the specified array.
JList(java.util.Vector items_)
          Construct a JList containing the items in the specified Vector.
 
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.
 java.lang.Object getSelectedValue()
          Get the first selected item on this list, or null if the selection is empty.
 java.lang.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_)
          Invoke all the KeyListener callbacks that may have been registered for this component.
 void processMouseEvent(MouseEvent e_)
          Process a MouseEvent that was generated by clicking the mouse somewhere inside this component.
 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()
          This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.
 void setColumns(int cols_)
          Set the number of columns INSIDE the list.
 void setListData(java.lang.Object[] listData_)
          Constructs a ListModel from an array of Objects and then applies setModel to it.
 void setListData(java.util.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
getBorder, getInsets, setBorder
 
Methods inherited from class charva.awt.Component
addFocusListener, addKeyListener, contains, contains, getAlignmentX, getAlignmentY, getAncestorWindow, getBackground, getBounds, getCursesColor, getForeground, getLocation, getLocationOnScreen, getName, getParent, hasFocus, hide, invalidate, isDisplayed, isEnabled, isFocusTraversable, isTotallyObscured, isValid, isVisible, processEvent, processFocusEvent, repaint, requestSync, setBackground, setBounds, setBounds, setBounds, setEnabled, setForeground, setLocation, setLocation, setName, setParent, setVisible, show, validate, validateCursesColor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface charva.awt.Scrollable
getLocation
 

Field Detail

_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)


_selectionModel

protected ListSelectionModel _selectionModel
The ListSelectionModel used by this JList.


_listModel

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

Constructor Detail

JList

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


JList

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


JList

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


JList

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

Method Detail

setListData

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


setListData

public void setListData(java.util.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.


getModel

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


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.


getVisibleRowCount

public int getVisibleRowCount()

setColumns

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


getSize

public Dimension getSize()
Specified by:
getSize in class Component

getWidth

public int getWidth()
Specified by:
getWidth in class Component

getHeight

public int getHeight()
Specified by:
getHeight in class Component

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns the size of the viewport needed to display visibleRows rows.

Specified by:
getPreferredScrollableViewportSize in interface Scrollable

setSelectionModel

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


getSelectionModel

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


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.


removeListSelectionListener

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


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 java.lang.Object getSelectedValue()
Get the first selected item on this list, or null if the selection is empty.


getSelectedValues

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


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


setSelectedIndex

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


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


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


clearSelection

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


getMinSelectionIndex

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


getMaxSelectionIndex

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


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.

getSelectionMode

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


isIndexSelected

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


minimumSize

public Dimension minimumSize()
Called by LayoutManager.

Specified by:
minimumSize in class Component

requestFocus

public void requestFocus()
Description copied from class: Component
This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.

Overrides:
requestFocus in class Component

draw

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

Overrides:
draw in class JComponent

processKeyEvent

public void processKeyEvent(KeyEvent ke_)
Description copied from class: Component
Invoke all the KeyListener callbacks that may have been registered for this component. The KeyListener objects may modify the keycodes, and can also set the "consumed" flag.

Overrides:
processKeyEvent in class Component

processMouseEvent

public void processMouseEvent(MouseEvent e_)
Description copied from class: Component
Process a MouseEvent that was generated by clicking the mouse somewhere inside this component.

Overrides:
processMouseEvent in class Component

addScrollListener

public void addScrollListener(ScrollListener sl_)
Register a ScrollListener object for this JList.

Specified by:
addScrollListener in interface Scrollable

removeScrollListener

public void removeScrollListener(ScrollListener sl_)
Remove a ScrollListener object that is registered for this JList.

Specified by:
removeScrollListener in interface Scrollable

processScrollEvent

public void processScrollEvent(ScrollEvent e_)
Process scroll events generated by this JList.

Specified by:
processScrollEvent in interface Scrollable

debug

public void debug(int level_)
Outputs a textual description of this component to stderr.

Specified by:
debug in class Component