All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.JList
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----com.sun.java.swing.JComponent
|
+----com.sun.java.swing.JList
- public class JList
- extends JComponent
- implements Accessible, Scrollable
A component that allows the user to select one or more objects from a
list. A separate model, ListModel
, represents the contents
of the list. It's easy to display an array or vector of objects, using
a JList constructor that builds an ListModel instance for you:
// Create a JList that displays the strings in data[]
String[] data = {"one", "two", "free", "four"};
JList dataList = new JList(data);
// The value JList model property is an object that provides
// a read-only view of the data. It was constructed automatically.
for(int i = 0; i < dataList.getModel().getSize(); i++) {
System.out.println(dataList.getModel().getElementAt(i));
}
// Create a JList that displays the superclass of JList.class.
// We store the superclasses in a java.util.Vector.
Vector superClasses = new Vector();
Class rootClass = com.sun.java.swing.JList.class;
for(Class cls = rootClass; cls != null; cls = cls.getSuperclass()) {
superClasses.addElement(cls);
}
JList classList = new JList(superClasses);
JList doesn't support scrolling directly. To create a scrolling
list you make the JList the viewport view of a JScrollPane, e.g.
JScrollPane scrollPane = new JScrollPane(dataList);
// Or in two steps:
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().setView(dataList);
By default JList supports single selection, i.e. zero or one
index can be selected. The selection state is actually managed
by a separate delegate object, an implementation of ListSelectionModel
however JList provides convenient properties for managing the selection.
String[] data = {"one", "two", "free", "four"};
JList dataList = new JList(data);
dataList.setSelectedIndex(1); // select "two"
dataList.getSelectedValue(); // returns "two"
The contents of a JList can be dynamic, i.e. the list elements can
change value and the size of the list can change after the JList has
been created. The JList observes changes in its model with a
ListModelListener
. A correct implementation of ListModel
will notify it's listeners each time a change occurs. The changes are
characterized by a ListModelEvent
that simply identifies
the range of List indices that have been modified, added, or removed.
Simple dynamic content JList applications can use the
DefaultListModel
class to store list elements. This class
implements the ListModel interfaces and provides all of the
java.util.Vector API as well. Applications that need to provide
custom ListModel implementations may want to subclass AbstractListModel,
which provides basic ListModelListener support. For example:
// This list model has about 2^16 elements. Enjoy scrolling.
ListModel bigData = new AbstractListModel() {
public int getSize() { return Short.MAX_VALUE; }
public Object getElementAt(int index) { return "Index " + index; }
};
JList bigDataList = new List(bigData);
// We don't want the JList implementation to compute the width
// or height of all of the list cells, so we give it a String
// that's as big as we'll need for any cell. It uses this to
// compute values for the fixedCellWidth and fixedCellHeight
// properties.
bigDataList.setPrototypeCellValue("Index 1234567890");
JList uses a java.awt.Component, provided by a delegate called the
cellRendererer
, to paint the visible cells in the list.
The cellRenderer component is used like a "rubber stamp" to paint
each visible row. Each time the JList needs to paint a cell
it asks the cellRenderer for the component, moves it into place
with setBounds() and then draws it by calling its paint method.
The default cellRenderer uses a JLabel component to render
the string value of each component. You can substitute your
own cellRenderer, e.g.:
// Display an icon and a string for each object in the list.
class MyCellRenderer extends JLabel implements ListCellRenderer {
final static ImageIcon longIcon = new ImageIcon("long.gif");
final static ImageIcon shortIcon = new ImageIcon("short.gif");
// This is the only method defined by ListCellRenderer. We just
// reconfigure the Jlabel each time we're called.
public Component getListCellRendererComponent(
JList list,
Object value, // value to display
int index, // cell index
boolean isSelected, // is the cell selected
boolean cellHasFocus) // the list and the cell have the focus
{
String s = value.toString();
setText(s);
setIcon((s.length > 10) ? longIcon : shortIcon);
return this;
}
}
String[] data = {"one", "two", "free", "four"};
JList dataList = new JList(data);
dataList.setCellRenderer(new MyCellRenderer());
JList doesn't provide any special support for handling doulble or
triple (or N) mouse clicks however it's easy to handle them using
a MouseListener. Just use the JList locationToIndex() method to
determine what cell was clicked on. For example:
final JList list = new JList(dataModel);
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = list.locationToIndex(e.getPoint());
System.out.println("Double clicked on Item " + index);
}
}
};
list.addMouseListener(mouseListener);
Note that in this example the JList variable is final
because it's referred to by the anonymous MouseListener class.
- See Also:
- ListModel, AbstractListModel, DefaultListModel, ListSelectionModel, DefaultListSelectionModel, ListCellRenderer
-
JList()
- Constructs a JList with an empty model.
-
JList(ListModel)
- Construct a JList that displays the elements in the specified,
non-null model.
-
JList(Object[])
- Construct a JList that displays the elements in the specified
array.
-
JList(Vector)
- Construct a JList that displays the elements in the specified
Vector.
-
addListSelectionListener(ListSelectionListener)
- Add a listener to the list that's notified each time a change
to the selection occurs.
-
addSelectionInterval(int, int)
- Set the selection to be the union of the specified interval with current
selection.
-
clearSelection()
- Clears the selection - after calling this method isSelectionEmpty()
will return true.
-
createSelectionModel()
- Returns an instance of DefaultListSelectionModel.
-
ensureIndexIsVisible(int)
- If this JList is being displayed withing a JViewport and the
specified cell isn't completely visible, scroll the viewport.
-
fireSelectionValueChanged(int, int, boolean)
- This method notifies JList ListSelectionListeners that
the selection model has changed.
-
getAccessibleAt(Point)
- Returns the Accessible child contained at the local coordinate
Point, if one exists.
-
getAccessibleChild(int)
- Return the nth Accessible child of the object.
-
getAccessibleChildrenCount()
- Returns the number of accessible children in the object.
-
getAccessibleRole()
- Get the role of this object.
-
getAccessibleStateSet()
- Get the state set of this object.
-
getAnchorSelectionIndex()
- Returns the first index argument from the most recent addSelectionInterval
or setSelectionInterval call.
-
getCellBounds(int, int)
-
Returns the bounds of the specified item in JList
coordinates, null if index isn't valid.
-
getCellRenderer()
-
-
getFirstVisibleIndex()
- Return the index of the cell in the upper left corner of the JList
or -1 if nothing is visible or the list is empty.
-
getFixedCellHeight()
-
-
getFixedCellWidth()
-
-
getLastVisibleIndex()
- Return the index of the cell in the lower right corner of the JList
or -1 if nothing is visible or the list is empty.
-
getLeadSelectionIndex()
- Returns the second index argument from the most recent addSelectionInterval
or setSelectionInterval call.
-
getMaxSelectionIndex()
- Returns the largest selected cell index.
-
getMinSelectionIndex()
- Returns the smallest selected cell index.
-
getModel()
-
-
getPreferredScrollableViewportSize()
- Compute the size of the viewport needed to display visibleRowCount
rows.
-
getPrototypeCellValue()
-
-
getScrollableBlockIncrement(Rectangle, int, int)
-
-
getScrollableTracksViewportHeight()
- If this JList is displayed in a JViewport, don't change its height
when the viewports height changes.
-
getScrollableTracksViewportWidth()
- If this JList is displayed in a JViewport, don't change its width
when the viewports width changes.
-
getScrollableUnitIncrement(Rectangle, int, int)
- If we're scrolling downwards (
direction
is
greater than 0), and the first row is completely visible with respect
to visibleRect
, then return its height.
-
getSelectedIndex()
- A convenience method that returns the first selected index.
-
getSelectedIndices()
- Return an array of all of the selected indices in increasing
order.
-
getSelectedValue()
- A convenience method that returns the first selected value
or null, if the selection is empty.
-
getSelectedValues()
- Return an array of the values for the selected cells.
-
getSelectionModel()
-
-
getUI()
-
-
getUIClassID()
-
-
getValueIsAdjusting(boolean)
-
-
getVisibleRowCount()
- Return the value of the visibleRowCount property.
-
indexToLocation(int)
-
Returns the origin of the specified item in JList
coordinates, null if index isn't valid.
-
isOpaque()
- JList components are always opaque.
-
isSelectedIndex(int)
- Returns true if the specified index is selected.
-
isSelectionEmpty()
- Returns true if nothing is selected
This is a convenience method that just delegates to the selectionModel.
-
locationToIndex(Point)
-
Convert a point in JList coordinates to the index
of the cell at that location.
-
removeListSelectionListener(ListSelectionListener)
- Remove a listener from the list that's notified each time a
change to the selection occurs.
-
removeSelectionInterval(int, int)
- Set the selection to be the set difference of the specified interval
and the current selection.
-
setCellRenderer(ListCellRenderer)
- Sets the delegate that's used to paint each cell in the list.
-
setFixedCellHeight(int)
-
If this value is greater than zero it defines the width of
every cell in the list.
-
setFixedCellWidth(int)
-
If this value is greater than zero it defines the width of
every cell in the list.
-
setListData(Object[])
- A convenience method that constructs a ListModel from the object array
and then applies setModel to it.
-
setListData(Vector)
- A convenience method that constructs a ListModel from the Vector
and then applies setModel to it.
-
setModel(ListModel)
- Sets the model that represents the contents or "value" of the
list and clears the lists selection after notifying PropertyChangeListeners.
-
setPrototypeCellValue(Object)
-
If this value is non-null it's used to compute fixedCellWidth
and fixedCellHeight by configuring the cellRenderer at index equals
zero for the specified value and then computing the renderer components
preferred size.
-
setSelectedIndex(int)
- Select a single cell.
-
setSelectedIndices(int[])
- Select a set of cells.
-
setSelectedValue(Object, boolean)
-
-
setSelectionInterval(int, int)
- Select the specified interval.
-
setSelectionModel(ListSelectionModel)
- Set the selectionModel for the list to a non null ListSelectionModel
implementation.
-
setUI(ListUI)
- Set the ListUI look and feel implementation delegate.
-
setValueIsAdjusting(boolean)
-
-
setVisibleRowCount(int)
- Set the preferred number of rows in the list that are visible within
the nearest JViewport ancestor, if any.
-
updateUI()
- Set the UI property with the "ListUI" from the current default
UIFactory.
JList
public JList(ListModel dataModel)
- Construct a JList that displays the elements in the specified,
non-null model. All JList constructors delegate to this one.
JList
public JList(Object listData[])
- Construct a JList that displays the elements in the specified
array. This constructor just delegates to the ListModel
constructor.
JList
public JList(Vector listData)
- Construct a JList that displays the elements in the specified
Vector. This constructor just delegates to the ListModel
constructor.
JList
public JList()
- Constructs a JList with an empty model.
getUI
public ListUI getUI()
- Returns:
- the value of the UI property.
- See Also:
- setUI
setUI
public void setUI(ListUI ui)
- Set the ListUI look and feel implementation delegate.
- See Also:
- getUI
updateUI
public void updateUI()
- Set the UI property with the "ListUI" from the current default
UIFactory. This method is called by the JList constructor and
to update the Lists look and feel at runtime.
- Overrides:
- updateUI in class JComponent
- See Also:
- getUI
getUIClassID
public String getUIClassID()
- Returns:
- "ListUI"
- Overrides:
- getUIClassID in class JComponent
- See Also:
- getUIClassID, getUI
isOpaque
public boolean isOpaque()
- JList components are always opaque.
- Returns:
- true
- Overrides:
- isOpaque in class JComponent
getPrototypeCellValue
public Object getPrototypeCellValue()
- Returns:
- the value of the prototypeCellValue property
- See Also:
- setPrototypeCellValue
setPrototypeCellValue
public void setPrototypeCellValue(Object prototypeCellValue)
- If this value is non-null it's used to compute fixedCellWidth
and fixedCellHeight by configuring the cellRenderer at index equals
zero for the specified value and then computing the renderer components
preferred size. This property is useful when the list is too long
to allow JList to just compute the width/height of each cell
and there's single cell value that's known to occupy as much space
as any of the others.
The default value of this property is null.
This is a JavaBeans bound property. Note that we do set
the fixedCellWidth and fixedCellHeight properties here but
only a prototypeCellValue PropertyChangeEvent is fired.
- Parameters:
- the - value to base fixedCellWidth and fixedCellHeight on.
- See Also:
- getPrototypeCellValue, setFixedCellWidth, setFixedCellHeight, addPropertyChangeEvent
getFixedCellWidth
public int getFixedCellWidth()
- Returns:
- the value of the fixedCellWidth property.
- See Also:
- setFixedCellWidth
setFixedCellWidth
public void setFixedCellWidth(int width)
- If this value is greater than zero it defines the width of
every cell in the list. Otherwise cell widths are computed
by applying getPreferredSize() to the cellRenderer component
for each list element.
The default value of this property is -1.
This is a JavaBeans bound property.
- Parameters:
- the - width for all cells in this list
- See Also:
- getPrototypeCellValue, setFixedCellWidth, addPropertyChangeEvent
getFixedCellHeight
public int getFixedCellHeight()
- Returns:
- the value of the fixedCellHeight property.
- See Also:
- setFixedCellHeight
setFixedCellHeight
public void setFixedCellHeight(int height)
- If this value is greater than zero it defines the width of
every cell in the list. Otherwise cell widths are computed
by applying getPreferredSize() to the cellRenderer component
for each list element.
The default value of this property is -1.
This is a JavaBeans bound property.
- Parameters:
- the - width for all cells in this list
- See Also:
- getPrototypeCellValue, setFixedCellWidth, addPropertyChangeEvent
getCellRenderer
public ListCellRenderer getCellRenderer()
- Returns:
- the value of the cellRenderer property.
- See Also:
- setCellRenderer
setCellRenderer
public void setCellRenderer(ListCellRenderer cellRenderer)
- Sets the delegate that's used to paint each cell in the list. If
prototypeCellValue was set then the fixedCellWidth and fixedCellHeight
properties are set as well. Only one PropertyChangeEvent is generated
however - for the "cellRenderer" property.
The default value of this property is provided by ListUI
delegate, i.e. by the look and feel implementation.
This is a JavaBeans bound property.
- See Also:
- createDefaultCellRenderer, getCellRenderer
getVisibleRowCount
public int getVisibleRowCount()
- Return the value of the visibleRowCount property.
- See Also:
- setVisibleRowCount
setVisibleRowCount
public void setVisibleRowCount(int visibleRowCount)
- Set the preferred number of rows in the list that are visible within
the nearest JViewport ancestor, if any. The value of this property
only affects the value of the JLists preferredScrollableViewportSize.
The default value of this property is 8.
This is a JavaBeans bound property.
- See Also:
- getVisibleRowCount, getVisibleRect
getFirstVisibleIndex
public int getFirstVisibleIndex()
- Return the index of the cell in the upper left corner of the JList
or -1 if nothing is visible or the list is empty. Note that this
cell may only be partially visible.
- Returns:
- The index of the first visible cell.
- See Also:
- getLastVisibleIndex, getVisibleRect
getLastVisibleIndex
public int getLastVisibleIndex()
- Return the index of the cell in the lower right corner of the JList
or -1 if nothing is visible or the list is empty. Note that this
cell may only be partially visible.
- Returns:
- The index of the last visible cell.
- See Also:
- getLastVisibleIndex, getVisibleRect
ensureIndexIsVisible
public void ensureIndexIsVisible(int index)
- If this JList is being displayed withing a JViewport and the
specified cell isn't completely visible, scroll the viewport.
- Parameters:
- The - index of the cell to make visible
- See Also:
- scrollRectToVisible, getVisibleRect
locationToIndex
public int locationToIndex(Point location)
- Convert a point in JList coordinates to the index
of the cell at that location. Returns -1 if there's no
cell the specified location.
- Parameters:
- location - The JList relative coordinates of the cell
- Returns:
- The index of the cell at location, or -1.
indexToLocation
public Point indexToLocation(int index)
- Returns the origin of the specified item in JList
coordinates, null if index isn't valid.
- Parameters:
- index - The index of the JList cell.
- Returns:
- The origin of the index'th cell.
getCellBounds
public Rectangle getCellBounds(int index1,
int index2)
- Returns the bounds of the specified item in JList
coordinates, null if index isn't valid.
- Parameters:
- index - The index of the JList cell.
- Returns:
- The bounds of the index'th cell.
getModel
public ListModel getModel()
- Returns:
- the value of the model property.
- See Also:
- setModel
setModel
public void setModel(ListModel model)
- Sets the model that represents the contents or "value" of the
list and clears the lists selection after notifying PropertyChangeListeners.
This is a JavaBeans bound property.
- See Also:
- getModel
setListData
public void setListData(Object listData[])
- A convenience method that constructs a ListModel from the object array
and then applies setModel to it.
- See Also:
- setModel
setListData
public void setListData(Vector listData)
- A convenience method that constructs a ListModel from the Vector
and then applies setModel to it.
- See Also:
- setModel
createSelectionModel
protected ListSelectionModel createSelectionModel()
- Returns an instance of DefaultListSelectionModel. This
method is used by the constructor to initialize the
selectionModel property.
- Returns:
- The ListSelectionModel used by this JList.
- See Also:
- setSelectionModel,
getSelectionModel
public ListSelectionModel getSelectionModel()
- Returns:
- the value of the selectionModel property
- See Also:
- setSelectionModel
fireSelectionValueChanged
protected void fireSelectionValueChanged(int firstIndex,
int lastIndex,
boolean isAdjusting)
- This method notifies JList ListSelectionListeners that
the selection model has changed. It's used to forward
ListSelectionEvents from the selectionModel to the
ListSelectionListeners added directly to the JList.
- See Also:
- addListSelectionModel, removeListSelectionModel, EventListenerList
addListSelectionListener
public void addListSelectionListener(ListSelectionListener listener)
- Add a listener to the list that's notified each time a change
to the selection occurs. Listeners added directly to the JList
will have their ListSelectionEvent.getSource() == this JList
(instead of the ListSelectionModel).
- Parameters:
- listener - The ListSelectionListener to add.
- See Also:
- getSelectionModel
removeListSelectionListener
public void removeListSelectionListener(ListSelectionListener listener)
- Remove a listener from the list that's notified each time a
change to the selection occurs.
- Parameters:
- listener - The ListSelectionListener to remove.
- See Also:
- addListSelectionListener, getSelectionModel
setSelectionModel
public void setSelectionModel(ListSelectionModel selectionModel)
- Set the selectionModel for the list to a non null ListSelectionModel
implementation.
This is a JavaBeans bound property.
- See Also:
- getSelectionModel
getAnchorSelectionIndex
public int getAnchorSelectionIndex()
- Returns the first index argument from the most recent addSelectionInterval
or setSelectionInterval call.
This is a convenience method that just delegates to the selectionModel.
- Returns:
- The index that most recently anchored an interval selection.
- See Also:
- getAnchorSelectionIndex, addSelectionInterval, setSelectionInterval, addListSelectionListener
getLeadSelectionIndex
public int getLeadSelectionIndex()
- Returns the second index argument from the most recent addSelectionInterval
or setSelectionInterval call.
This is a convenience method that just delegates to the selectionModel.
- Returns:
- The index that most recently ended a interval selection.
- See Also:
- getLeadSelectionIndex, addSelectionInterval, setSelectionInterval, addListSelectionListener
getMinSelectionIndex
public int getMinSelectionIndex()
- Returns the smallest selected cell index.
This is a convenience method that just delegates to the selectionModel.
- Returns:
- The smallest selected cell index.
- See Also:
- getMinSelectionIndex, addListSelectionListener
getMaxSelectionIndex
public int getMaxSelectionIndex()
- Returns the largest selected cell index.
This is a convenience method that just delegates to the selectionModel.
- Returns:
- The largest selected cell index.
- See Also:
- getMaxSelectionIndex, addListSelectionListener
isSelectedIndex
public boolean isSelectedIndex(int index)
- Returns true if the specified index is selected.
This is a convenience method that just delegates to the selectionModel.
- Returns:
- True if the specified index is selected.
- See Also:
- isSelectedIndex, setSelectedIndex, addListSelectionListener
isSelectionEmpty
public boolean isSelectionEmpty()
- Returns true if nothing is selected
This is a convenience method that just delegates to the selectionModel.
- Returns:
- True if nothing is selected
- See Also:
- isSelectionEmpty, clearSelection, addListSelectionListener
clearSelection
public void clearSelection()
- Clears the selection - after calling this method isSelectionEmpty()
will return true.
This is a convenience method that just delegates to the selectionModel.
- See Also:
- clearSelection, isSelectionEmpty, addListSelectionListener
setSelectionInterval
public void setSelectionInterval(int anchor,
int lead)
- Select the specified interval. Both the anchor and lead indices are
included. It's not neccessary for anchor to be less than lead.
This is a convenience method that just delegates to the selectionModel.
- Parameters:
- anchor - The first index to select
- lead - The last index to select
- See Also:
- setSelectionInterval, addSelectionInterval, removeSelectionInterval, addListSelectionListener
addSelectionInterval
public void addSelectionInterval(int anchor,
int lead)
- Set the selection to be the union of the specified interval with current
selection. Both the anchor and lead indices are
included. It's not neccessary for anchor to be less than lead.
This is a convenience method that just delegates to the selectionModel.
- Parameters:
- anchor - The first index to add to the selection
- lead - The last index to add to the selection
- See Also:
- addSelectionInterval, setSelectionInterval, removeSelectionInterval, addListSelectionListener
removeSelectionInterval
public void removeSelectionInterval(int index0,
int index1)
- Set the selection to be the set difference of the specified interval
and the current selection. Both the anchor and lead indices are
removed. It's not neccessary for anchor to be less than lead.
This is a convenience method that just delegates to the selectionModel.
- Parameters:
- anchor - The first index to remove from the selection
- lead - The last index to remove from the selection
- See Also:
- removeSelectionInterval, setSelectionInterval, addSelectionInterval, addListSelectionListener
setValueIsAdjusting
public void setValueIsAdjusting(boolean b)
getValueIsAdjusting
public boolean getValueIsAdjusting(boolean b)
getSelectedIndices
public int[] getSelectedIndices()
- Return an array of all of the selected indices in increasing
order.
- Returns:
- All of the selected indices, in increasing order.
- See Also:
- removeSelectionInterval, addListSelectionListener
setSelectedIndex
public void setSelectedIndex(int index)
- Select a single cell.
- Parameters:
- index - The index of the one cell to select
- See Also:
- setSelectionInterval, isSelectedIndex, addListSelectionListener
setSelectedIndices
public void setSelectedIndices(int indices[])
- Select a set of cells.
- Parameters:
- indices - The indices of the cells to select
- See Also:
- addSelectionInterval, isSelectedIndex, addListSelectionListener
getSelectedValues
public Object[] getSelectedValues()
- Return an array of the values for the selected cells.
The returned values are sorted in increasing index order.
- Returns:
- the selected values
- See Also:
- isSelectedIndex, getModel, addListSelectionListener
getSelectedIndex
public int getSelectedIndex()
- A convenience method that returns the first selected index.
- Returns:
- The first selected index.
- See Also:
- getMinSelectionIndex, addListSelectionListener
getSelectedValue
public Object getSelectedValue()
- A convenience method that returns the first selected value
or null, if the selection is empty.
- Returns:
- The first selected value.
- See Also:
- getMinSelectionIndex, getModel, addListSelectionListener
setSelectedValue
public void setSelectedValue(Object anObject,
boolean shouldScroll)
getAccessibleStateSet
public AccessibleStateSet getAccessibleStateSet()
- Get the state set of this object.
- Returns:
- an instance of AccessibleState containing the current state
of the object
- Overrides:
- getAccessibleStateSet in class JComponent
- See Also:
- AccessibleState
getAccessibleRole
public AccessibleRole getAccessibleRole()
- Get the role of this object.
- Returns:
- an instance of AccessibleRole describing the role of the object
- Overrides:
- getAccessibleRole in class JComponent
- See Also:
- AccessibleRole
getAccessibleAt
public Accessible getAccessibleAt(Point p)
- Returns the Accessible child contained at the local coordinate
Point, if one exists.
- Returns:
- the Accessible at the specified location, if it exists
- Overrides:
- getAccessibleAt in class JComponent
getAccessibleChildrenCount
public int getAccessibleChildrenCount()
- Returns the number of accessible children in the object. If all
of the children of this object implement Accessible, than this
method should return the number of children of this object.
- Returns:
- the number of accessible children in the object.
- Overrides:
- getAccessibleChildrenCount in class JComponent
getAccessibleChild
public Accessible getAccessibleChild(int i)
- Return the nth Accessible child of the object.
- Parameters:
- i - zero-based index of child
- Returns:
- the nth Accessible child of the object
- Overrides:
- getAccessibleChild in class JComponent
getPreferredScrollableViewportSize
public Dimension getPreferredScrollableViewportSize()
- Compute the size of the viewport needed to display visibleRowCount
rows. This is trivial if fixedCellWidth and fixedCellHeight
were specified. Note that they can specified implicitly with
the prototypeCellValue property. If fixedCellWidth wasn't specified,
it's computed by finding the widest list element. If fixedCellHeight
wasn't specified then we resort to heuristics:
-
If the model isn't empty we just multiply the height of the first row
by visibleRowCount.
-
If the model is empty, i.e. JList.getModel().getSize() == 0, then
we just allocate 16 pixels per visible row, and 100 pixels
for the width (unless fixedCellWidth was set), and hope for the best.
- See Also:
- getPreferredScrollableViewportSize, setPrototypeCellValue
getScrollableUnitIncrement
public int getScrollableUnitIncrement(Rectangle visibleRect,
int orientation,
int direction)
- If we're scrolling downwards (
direction
is
greater than 0), and the first row is completely visible with respect
to visibleRect
, then return its height. If
we're scrolling downwards and the first row is only partially visible,
return the height of the visible part of the first row. Similarly
if we're scrolling upwards we return the height of the row above
the first row, unless the first row is partially visible.
- Returns:
- The distance to scroll to expose the next or previous row.
- See Also:
- getScrollableUnitIncrement
getScrollableBlockIncrement
public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation,
int direction)
- Returns:
- The visibleRect.height or visibleRect.width per the orientation.
- See Also:
- getScrollableUnitIncrement
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()
- If this JList is displayed in a JViewport, don't change its width
when the viewports width changes. This allows horizontal
scrolling if the JViewport is itself embedded in a JScrollPane.
- Returns:
- False - don't track the viewports width.
- See Also:
- getScrollableTracksViewportWidth
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()
- If this JList is displayed in a JViewport, don't change its height
when the viewports height changes. This allows vertical
scrolling if the JViewport is itself embedded in a JScrollPane.
- Returns:
- False - don't track the viewports width.
- See Also:
- getScrollableTracksViewportWidth
All Packages Class Hierarchy This Package Previous Next Index