List component in which list items are layed out as cells in a grid.
The functionality is the same
as that of
javax.swing.JList
except for the following:
- We use a different cell layout and visual representation.
- Selection properties should be obtained directly from the selection
model. We do not provide proxy methods except
getSelectedValue()
and getSelectedValues()
. - Although drag and drop is enabled, we do not provide a default
transfer handler.
This list component uses a
cellRenderer
delegate of type
CellListCellRenderer
to paint the visible cells in the list
and to obtain the correct tool tip information for that cell.
contentsChanged
public void contentsChanged(ListDataEvent e)
ensureIndexIsVisible
public void ensureIndexIsVisible(int index)
Scrolls the viewport to make the specified cell completely visible.
Only works when the list is in a scroll pane.
index
- the index of the cell to make visible
getCellBounds
public Rectangle getCellBounds(int index0,
int index1)
Returns the bounds of the specified range of items in component
coordinates.Returns null
if index isn't valid.
index0
- the index of the first cell in the rangeindex1
- the index of the last cell in the range
- the bounds of the indexed cells in pixels
getCellHeight
public int getCellHeight()
Height of a grid cell.
- Value of property cellHeight.
getCellRenderer
public CellListCellRenderer getCellRenderer()
Return the cell renderer used by this list.
getCellWidth
public int getCellWidth()
Width of a grid cell.
- Value of property cellWidth.
getDropLocation
public Point getDropLocation()
Return the last drag-and-drop location where this component is a target.
getMinimumSize
public Dimension getMinimumSize()
getModel
public ListModel getModel()
Return the current data model.
getPreferredScrollableViewportSize
public Dimension getPreferredScrollableViewportSize()
getPreferredSize
public Dimension getPreferredSize()
getScrollableBlockIncrement
public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation,
int direction)
Returns the distance to scroll vertically to expose the next or previous block.
We are using the follows rules:
- If scrolling down,
the last visible row should become the first completely
visible row.
- If scrolling up, the first visible row should become the last
completely visible row.
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()
getScrollableUnitIncrement
public int getScrollableUnitIncrement(Rectangle visibleRect,
int orientation,
int direction)
Returns the distance to scroll vertically to expose the next or previous
row. If the top (resp. bottom) row was only partially exposed
it now becomes fully exposed.
getSelectedValue
public Object getSelectedValue()
Returns the first selected value, or null
if the
selection is empty.
getSelectedValues
public Object[] getSelectedValues()
Returns an array of the values for the selected cells.
The returned values are sorted in increasing index order.
getSelectionModel
public ListSelectionModel getSelectionModel()
Return the current selection model.
getToolTipText
public String getToolTipText(MouseEvent event)
Overrides JComponent
's getToolTipText
method in order to allow the renderer's tips to be used
if it has text set.
JComponent.getToolTipText
indexToLocation
public Point indexToLocation(int index)
Return the top left coordinate of the cell with given index,
or null
if the index is not valid.
initActionMap
public final void initActionMap()
Initialize the action map.
intervalAdded
public void intervalAdded(ListDataEvent e)
intervalRemoved
public void intervalRemoved(ListDataEvent e)
isDragEnabled
public boolean isDragEnabled()
Is dragging on this component enabled?
isDropInProgress
public boolean isDropInProgress()
Is a drag-and-drop operation in progress where
this component is a target?
locationToIndex
public int locationToIndex(Point location)
Convert a point in component coordinates to the index of the
cell at that location, or -1 if there is no such cell.
setCellHeight
public void setCellHeight(int cellHeight)
Set the height of a grid cell.
cellHeight
- New value of property cellHeight.
setCellRenderer
public void setCellRenderer(CellListCellRenderer cellRenderer)
Set the cell renderer.
setCellSize
public void setCellSize(int cellWidth,
int cellHeight)
Set width and height of a grid cell.
cellWidth
- New value of property cellWidth.cellHeight
- New value of property cellHeight.
setCellWidth
public void setCellWidth(int cellWidth)
Set the width of a grid cell.
cellWidth
- New value of property cellWidth.
setDragEnabled
public void setDragEnabled(boolean dragEnabled)
Indicate whether dragging on this component should be enabled.
setDropTarget
public void setDropTarget(DropTarget dt)
setModel
public void setModel(ListModel model)
Sets a new data model and clears the selection.
setNumberOfColumns
public void setNumberOfColumns(int numberOfColumns)
Set the number of columns to use in this list.
numberOfColumns
- New value of property numberOfColumns.
setSelectionModel
public final void setSelectionModel(ListSelectionModel selectionModel)
Set or change the selection model.
void doLayout
public @Override void doLayout()
void paintComponent
protected @Override void paintComponent(Graphics g)