next up previous
Next: Trees JTree Up: List JList Previous: JList constructors

JList important methods

The following methods managed the cell prototype value. The prototype value is used to calculate the width of each cell in the list. Using a cell prototype is much more efficient than inspecting each item in the list to determine the maximum width.

public Object getPrototypeCellValue()
public void setPrototypeCellValue(Object prototypeCellValue)

The following methods are used to determine and control the width and height of each cell in the list:

public int getFixedCellWidth()
public void setFixedCellWidth( int width )
public int getFixedCellHeight()
public void setFixedCellHeight( int height )

The following methods manage the delegate class used to paint each cell in the list:

public ListCellRenderer getCellRenderer()
public void setCellRenderer( ListCellRenderer cellRenderer )

The following methods manage the foreground and background colors used to display the currently selected item. A custom cell renderer can override these values, or that renderer can reference these colors during a painting operation.

public Color getSelectionForeground()
public void setSelectionForeground(Color selectionForeground)
public Color getSelectionBackground()
public void setSelectionBackground(Color selectionBackground)

The following methods detect and control the number of rows visible within a list. The row count (overall height) of a JList instance can be managed at run time with these methods.

public int getVisibleRowCount()
public void setVisibleRowCount(int visibleRowCount)

The following methods are used to determine the index of the first or last index visible in the list. Additionally, the ensureIndexIsVisible() method can force any item into the visible region of the list.

public int getFirstVisibleIndex()
public int getLastVisibleIndex()
public void ensureIndexIsVisible( int index )

The following methods are used to calculate the correlation of a list item, referenced by index, and an actual pixel location within the list. These methods are typically used to determine which item is currently under the mouse pointer.

public int locationToIndex( Point location )
public Point indexToLocation( int index )

The public Rectangle getCellBounds( int index1, int index2 ) method returns a rectangular region bound by two list items specified by index numbers.

The following methods are used to manage the data referenced in the list. Data can be stored within a custom data model, a simple array, or a vectored array. Any time data is changed dynamically, one of the set method shown here must be called to update the list.

public ListModel getModel()
public void setModel( ListModel model )
public void setListData( Object listData[] )
public void setListData( Vector listData )

The following methods manage the presence of a list selection listener for the current JList instance. A list selection listener intercepts events generated by the list object when the user changes the current selection.

public void addListSelectionListener(ListSelectionListener listener)
public void removeListSelectionListener(
ListSelectionListener listener)

The following methods control the selection mode used in the list instance:

public int getSelectionMode()
public void setSelectionMode(int selectionMode)

The mode is limited to:

SINGLE_SELECTION
-- for selecting only one item at a time
SINGLE_INTERVAL_SELECTION
-- to allow selection of single contiguous blocks of items
MULTIPLE_INTERVAL_SELECTION
-- to allow multiple item or block selection

The following methods return list indices based on various restrictions. For example, the first selected item in a range of selections can be determined with the getAnchorSelectionIndex() method.

public int getAnchorSelectionIndex()
public int getLeadSelectionIndex()
public int getMinSelectionIndex()
public int getMaxSelectionIndex()

The following methods manage information about the selections within the list object. Additionally, selections can be added or removed with methods from this group.

public boolean isSelectedIndex(int index)
public boolean isSelectionEmpty()
public void clearSelection()
public int[] getSelectedIndices()
public void setSelectedIndex(int index)
public void setSelectedIndices(int indices[])
public Object[] getSelectedValues()
public int getSelectedIndex()
public Object getSelectedValue()
public void setSelectedValue( Object anObject, boolean shouldScroll )
public void setSelectionInterval( int anchor, int lead )
public void addSelectionInterval( int anchor, int lead )
public void removeSelectionInterval( int index0, int index1 )

The final two methods manage the state of the is value adjusting flag.

public void setValueIsAdjusting(boolean b)
public boolean getValueIsAdjusting(boolean b)


next up previous
Next: Trees JTree Up: List JList Previous: JList constructors
Dave Marshall
4/14/1999