jdk/src/share/classes/javax/swing/JList.java
Print this page
*** 20,30 ****
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-
package javax.swing;
import java.awt.*;
import java.awt.event.*;
--- 20,29 ----
*** 32,60 ****
import java.util.Locale;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.Transient;
import javax.swing.event.*;
import javax.accessibility.*;
import javax.swing.plaf.*;
import javax.swing.text.Position;
import java.io.ObjectOutputStream;
- import java.io.ObjectInputStream;
import java.io.IOException;
import java.io.Serializable;
import sun.swing.SwingUtilities2;
import sun.swing.SwingUtilities2.Section;
import static sun.swing.SwingUtilities2.Section.*;
-
/**
* A component that displays a list of objects and allows the user to select
* one or more items. A separate model, {@code ListModel}, maintains the
* contents of the list.
* <p>
--- 31,59 ----
import java.util.Locale;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+ import java.beans.JavaBean;
+ import java.beans.BeanProperty;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.Transient;
import javax.swing.event.*;
import javax.accessibility.*;
import javax.swing.plaf.*;
import javax.swing.text.Position;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.io.Serializable;
import sun.swing.SwingUtilities2;
import sun.swing.SwingUtilities2.Section;
import static sun.swing.SwingUtilities2.Section.*;
/**
* A component that displays a list of objects and allows the user to select
* one or more items. A separate model, {@code ListModel}, maintains the
* contents of the list.
* <p>
*** 269,285 ****
* @see ListCellRenderer
* @see DefaultListCellRenderer
*
* @param <E> the type of the elements of this list
*
- * @beaninfo
- * attribute: isContainer false
- * description: A component which allows for the selection of one or more objects from a list.
- *
* @author Hans Muller
* @since 1.2
*/
@SuppressWarnings("serial") // Same-version serialization only
public class JList<E> extends JComponent implements Scrollable, Accessible
{
/**
* @see #getUIClassID
--- 268,282 ----
* @see ListCellRenderer
* @see DefaultListCellRenderer
*
* @param <E> the type of the elements of this list
*
* @author Hans Muller
* @since 1.2
*/
+ @JavaBean(defaultProperty = "UI", description = "A component which allows for the selection of one or more objects from a list.")
+ @SwingContainer(false)
@SuppressWarnings("serial") // Same-version serialization only
public class JList<E> extends JComponent implements Scrollable, Accessible
{
/**
* @see #getUIClassID
*** 513,528 ****
* Sets the {@code ListUI}, the look and feel object that
* renders this component.
*
* @param ui the <code>ListUI</code> object
* @see UIDefaults#getUI
- * @beaninfo
- * bound: true
- * hidden: true
- * attribute: visualUpdate true
- * description: The UI object that implements the Component's LookAndFeel.
*/
public void setUI(ListUI ui) {
super.setUI(ui);
}
--- 510,522 ----
* Sets the {@code ListUI}, the look and feel object that
* renders this component.
*
* @param ui the <code>ListUI</code> object
* @see UIDefaults#getUI
*/
+ @BeanProperty(hidden = true, visualUpdate = true, description
+ = "The UI object that implements the Component's LookAndFeel.")
public void setUI(ListUI ui) {
super.setUI(ui);
}
*** 553,562 ****
--- 547,557 ----
*
* @return the string "ListUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
+ @BeanProperty(bound = false)
public String getUIClassID() {
return uiClassID;
}
*** 638,652 ****
* <code>fixedCellHeight</code>
* @see #getPrototypeCellValue
* @see #setFixedCellWidth
* @see #setFixedCellHeight
* @see JComponent#addPropertyChangeListener
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: The cell prototype value, used to compute cell width and height.
*/
public void setPrototypeCellValue(E prototypeCellValue) {
E oldValue = this.prototypeCellValue;
this.prototypeCellValue = prototypeCellValue;
/* If the prototypeCellValue has changed and is non-null,
--- 633,645 ----
* <code>fixedCellHeight</code>
* @see #getPrototypeCellValue
* @see #setFixedCellWidth
* @see #setFixedCellHeight
* @see JComponent#addPropertyChangeListener
*/
+ @BeanProperty(visualUpdate = true, description
+ = "The cell prototype value, used to compute cell width and height.")
public void setPrototypeCellValue(E prototypeCellValue) {
E oldValue = this.prototypeCellValue;
this.prototypeCellValue = prototypeCellValue;
/* If the prototypeCellValue has changed and is non-null,
*** 683,697 ****
*
* @param width the width to be used for all cells in the list
* @see #setPrototypeCellValue
* @see #setFixedCellWidth
* @see JComponent#addPropertyChangeListener
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: Defines a fixed cell width when greater than zero.
*/
public void setFixedCellWidth(int width) {
int oldValue = fixedCellWidth;
fixedCellWidth = width;
firePropertyChange("fixedCellWidth", oldValue, fixedCellWidth);
}
--- 676,688 ----
*
* @param width the width to be used for all cells in the list
* @see #setPrototypeCellValue
* @see #setFixedCellWidth
* @see JComponent#addPropertyChangeListener
*/
+ @BeanProperty(visualUpdate = true, description
+ = "Defines a fixed cell width when greater than zero.")
public void setFixedCellWidth(int width) {
int oldValue = fixedCellWidth;
fixedCellWidth = width;
firePropertyChange("fixedCellWidth", oldValue, fixedCellWidth);
}
*** 719,733 ****
*
* @param height the height to be used for for all cells in the list
* @see #setPrototypeCellValue
* @see #setFixedCellWidth
* @see JComponent#addPropertyChangeListener
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: Defines a fixed cell height when greater than zero.
*/
public void setFixedCellHeight(int height) {
int oldValue = fixedCellHeight;
fixedCellHeight = height;
firePropertyChange("fixedCellHeight", oldValue, fixedCellHeight);
}
--- 710,722 ----
*
* @param height the height to be used for for all cells in the list
* @see #setPrototypeCellValue
* @see #setFixedCellWidth
* @see JComponent#addPropertyChangeListener
*/
+ @BeanProperty(visualUpdate = true, description
+ = "Defines a fixed cell height when greater than zero.")
public void setFixedCellHeight(int height) {
int oldValue = fixedCellHeight;
fixedCellHeight = height;
firePropertyChange("fixedCellHeight", oldValue, fixedCellHeight);
}
*** 761,775 ****
* This is a JavaBeans bound property.
*
* @param cellRenderer the <code>ListCellRenderer</code>
* that paints list cells
* @see #getCellRenderer
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: The component used to draw the cells.
*/
public void setCellRenderer(ListCellRenderer<? super E> cellRenderer) {
ListCellRenderer<? super E> oldValue = this.cellRenderer;
this.cellRenderer = cellRenderer;
/* If the cellRenderer has changed and prototypeCellValue
--- 750,762 ----
* This is a JavaBeans bound property.
*
* @param cellRenderer the <code>ListCellRenderer</code>
* that paints list cells
* @see #getCellRenderer
*/
+ @BeanProperty(visualUpdate = true, description
+ = "The component used to draw the cells.")
public void setCellRenderer(ListCellRenderer<? super E> cellRenderer) {
ListCellRenderer<? super E> oldValue = this.cellRenderer;
this.cellRenderer = cellRenderer;
/* If the cellRenderer has changed and prototypeCellValue
*** 816,830 ****
* @see #setSelectionBackground
* @see #setForeground
* @see #setBackground
* @see #setFont
* @see DefaultListCellRenderer
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: The foreground color of selected cells.
*/
public void setSelectionForeground(Color selectionForeground) {
Color oldValue = this.selectionForeground;
this.selectionForeground = selectionForeground;
firePropertyChange("selectionForeground", oldValue, selectionForeground);
}
--- 803,815 ----
* @see #setSelectionBackground
* @see #setForeground
* @see #setBackground
* @see #setFont
* @see DefaultListCellRenderer
*/
+ @BeanProperty(visualUpdate = true, description
+ = "The foreground color of selected cells.")
public void setSelectionForeground(Color selectionForeground) {
Color oldValue = this.selectionForeground;
this.selectionForeground = selectionForeground;
firePropertyChange("selectionForeground", oldValue, selectionForeground);
}
*** 863,877 ****
* @see #setSelectionForeground
* @see #setForeground
* @see #setBackground
* @see #setFont
* @see DefaultListCellRenderer
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: The background color of selected cells.
*/
public void setSelectionBackground(Color selectionBackground) {
Color oldValue = this.selectionBackground;
this.selectionBackground = selectionBackground;
firePropertyChange("selectionBackground", oldValue, selectionBackground);
}
--- 848,860 ----
* @see #setSelectionForeground
* @see #setForeground
* @see #setBackground
* @see #setFont
* @see DefaultListCellRenderer
*/
+ @BeanProperty(visualUpdate = true, description
+ = "The background color of selected cells.")
public void setSelectionBackground(Color selectionBackground) {
Color oldValue = this.selectionBackground;
this.selectionBackground = selectionBackground;
firePropertyChange("selectionBackground", oldValue, selectionBackground);
}
*** 918,933 ****
* @see #getVisibleRowCount
* @see #getPreferredScrollableViewportSize
* @see #setLayoutOrientation
* @see JComponent#getVisibleRect
* @see JViewport
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: The preferred number of rows to display without
- * requiring scrolling
*/
public void setVisibleRowCount(int visibleRowCount) {
int oldValue = this.visibleRowCount;
this.visibleRowCount = Math.max(0, visibleRowCount);
firePropertyChange("visibleRowCount", oldValue, visibleRowCount);
}
--- 901,913 ----
* @see #getVisibleRowCount
* @see #getPreferredScrollableViewportSize
* @see #setLayoutOrientation
* @see JComponent#getVisibleRect
* @see JViewport
*/
+ @BeanProperty(visualUpdate = true, description
+ = "The preferred number of rows to display without requiring scrolling")
public void setVisibleRowCount(int visibleRowCount) {
int oldValue = this.visibleRowCount;
this.visibleRowCount = Math.max(0, visibleRowCount);
firePropertyChange("visibleRowCount", oldValue, visibleRowCount);
}
*** 997,1014 ****
* @see #getScrollableTracksViewportHeight
* @see #getScrollableTracksViewportWidth
* @throws IllegalArgumentException if {@code layoutOrientation} isn't one of the
* allowable values
* @since 1.4
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: Defines the way list cells are layed out.
- * enum: VERTICAL JList.VERTICAL
- * HORIZONTAL_WRAP JList.HORIZONTAL_WRAP
- * VERTICAL_WRAP JList.VERTICAL_WRAP
*/
public void setLayoutOrientation(int layoutOrientation) {
int oldValue = this.layoutOrientation;
switch (layoutOrientation) {
case VERTICAL:
case VERTICAL_WRAP:
--- 977,992 ----
* @see #getScrollableTracksViewportHeight
* @see #getScrollableTracksViewportWidth
* @throws IllegalArgumentException if {@code layoutOrientation} isn't one of the
* allowable values
* @since 1.4
*/
+ @BeanProperty(visualUpdate = true, enumerationValues = {
+ "JList.VERTICAL",
+ "JList.HORIZONTAL_WRAP",
+ "JList.VERTICAL_WRAP"}, description
+ = "Defines the way list cells are layed out.")
public void setLayoutOrientation(int layoutOrientation) {
int oldValue = this.layoutOrientation;
switch (layoutOrientation) {
case VERTICAL:
case VERTICAL_WRAP:
*** 1032,1041 ****
--- 1010,1020 ----
*
* @return the index of the first visible cell
* @see #getLastVisibleIndex
* @see JComponent#getVisibleRect
*/
+ @BeanProperty(bound = false)
public int getFirstVisibleIndex() {
Rectangle r = getVisibleRect();
int first;
if (this.getComponentOrientation().isLeftToRight()) {
first = locationToIndex(r.getLocation());
*** 1062,1071 ****
--- 1041,1051 ----
*
* @return the index of the last visible cell
* @see #getFirstVisibleIndex
* @see JComponent#getVisibleRect
*/
+ @BeanProperty(bound = false)
public int getLastVisibleIndex() {
boolean leftToRight = this.getComponentOrientation().isLeftToRight();
Rectangle r = getVisibleRect();
Point lastPoint;
if (leftToRight) {
*** 1178,1192 ****
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #getDragEnabled
* @see #setTransferHandler
* @see TransferHandler
* @since 1.4
- *
- * @beaninfo
- * description: determines whether automatic drag handling is enabled
- * bound: false
*/
public void setDragEnabled(boolean b) {
if (b && GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
dragEnabled = b;
--- 1158,1170 ----
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #getDragEnabled
* @see #setTransferHandler
* @see TransferHandler
* @since 1.4
*/
+ @BeanProperty(bound = false, description
+ = "determines whether automatic drag handling is enabled")
public void setDragEnabled(boolean b) {
if (b && GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
dragEnabled = b;
*** 1447,1456 ****
--- 1425,1435 ----
* @return the drop location
* @see #setDropMode
* @see TransferHandler#canImport(TransferHandler.TransferSupport)
* @since 1.6
*/
+ @BeanProperty(bound = false)
public final DropLocation getDropLocation() {
return dropLocation;
}
/**
*** 1662,1676 ****
* list of items for display
* @exception IllegalArgumentException if <code>model</code> is
* <code>null</code>
* @see #getModel
* @see #clearSelection
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: The object that contains the data to be drawn by this JList.
*/
public void setModel(ListModel<E> model) {
if (model == null) {
throw new IllegalArgumentException("model must be non null");
}
ListModel<E> oldValue = dataModel;
--- 1641,1653 ----
* list of items for display
* @exception IllegalArgumentException if <code>model</code> is
* <code>null</code>
* @see #getModel
* @see #clearSelection
*/
+ @BeanProperty(visualUpdate = true, description
+ = "The object that contains the data to be drawn by this JList.")
public void setModel(ListModel<E> model) {
if (model == null) {
throw new IllegalArgumentException("model must be non null");
}
ListModel<E> oldValue = dataModel;
*** 1858,1867 ****
--- 1835,1845 ----
* @return all of the {@code ListSelectionListener}s on this list, or
* an empty array if no listeners have been added
* @see #addListSelectionListener
* @since 1.4
*/
+ @BeanProperty(bound = false)
public ListSelectionListener[] getListSelectionListeners() {
return listenerList.getListeners(ListSelectionListener.class);
}
*** 1877,1890 ****
* @param selectionModel the <code>ListSelectionModel</code> that
* implements the selections
* @exception IllegalArgumentException if <code>selectionModel</code>
* is <code>null</code>
* @see #getSelectionModel
- * @beaninfo
- * bound: true
- * description: The selection model, recording which cells are selected.
*/
public void setSelectionModel(ListSelectionModel selectionModel) {
if (selectionModel == null) {
throw new IllegalArgumentException("selectionModel must be non null");
}
--- 1855,1867 ----
* @param selectionModel the <code>ListSelectionModel</code> that
* implements the selections
* @exception IllegalArgumentException if <code>selectionModel</code>
* is <code>null</code>
* @see #getSelectionModel
*/
+ @BeanProperty(description
+ = "The selection model, recording which cells are selected.")
public void setSelectionModel(ListSelectionModel selectionModel) {
if (selectionModel == null) {
throw new IllegalArgumentException("selectionModel must be non null");
}
*** 1926,1941 ****
*
* @param selectionMode the selection mode
* @see #getSelectionMode
* @throws IllegalArgumentException if the selection mode isn't
* one of those allowed
- * @beaninfo
- * description: The selection mode.
- * enum: SINGLE_SELECTION ListSelectionModel.SINGLE_SELECTION
- * SINGLE_INTERVAL_SELECTION ListSelectionModel.SINGLE_INTERVAL_SELECTION
- * MULTIPLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
*/
public void setSelectionMode(int selectionMode) {
getSelectionModel().setSelectionMode(selectionMode);
}
/**
--- 1903,1918 ----
*
* @param selectionMode the selection mode
* @see #getSelectionMode
* @throws IllegalArgumentException if the selection mode isn't
* one of those allowed
*/
+ @BeanProperty(bound = false, enumerationValues = {
+ "ListSelectionModel.SINGLE_SELECTION",
+ "ListSelectionModel.SINGLE_INTERVAL_SELECTION",
+ "ListSelectionModel.MULTIPLE_INTERVAL_SELECTION"}, description
+ = "The selection mode.")
public void setSelectionMode(int selectionMode) {
getSelectionModel().setSelectionMode(selectionMode);
}
/**
*** 1956,1965 ****
--- 1933,1943 ----
* delegates to the method of the same name on the list's selection model.
*
* @return the anchor selection index
* @see ListSelectionModel#getAnchorSelectionIndex
*/
+ @BeanProperty(bound = false)
public int getAnchorSelectionIndex() {
return getSelectionModel().getAnchorSelectionIndex();
}
*** 1967,1979 ****
* Returns the lead selection index. This is a cover method that
* delegates to the method of the same name on the list's selection model.
*
* @return the lead selection index
* @see ListSelectionModel#getLeadSelectionIndex
- * @beaninfo
- * description: The lead selection index.
*/
public int getLeadSelectionIndex() {
return getSelectionModel().getLeadSelectionIndex();
}
--- 1945,1957 ----
* Returns the lead selection index. This is a cover method that
* delegates to the method of the same name on the list's selection model.
*
* @return the lead selection index
* @see ListSelectionModel#getLeadSelectionIndex
*/
+ @BeanProperty(bound = false, description
+ = "The lead selection index.")
public int getLeadSelectionIndex() {
return getSelectionModel().getLeadSelectionIndex();
}
*** 1983,1992 ****
--- 1961,1971 ----
* name on the list's selection model.
*
* @return the smallest selected cell index, or {@code -1}
* @see ListSelectionModel#getMinSelectionIndex
*/
+ @BeanProperty(bound = false)
public int getMinSelectionIndex() {
return getSelectionModel().getMinSelectionIndex();
}
*** 1996,2005 ****
--- 1975,1985 ----
* name on the list's selection model.
*
* @return the largest selected cell index
* @see ListSelectionModel#getMaxSelectionIndex
*/
+ @BeanProperty(bound = false)
public int getMaxSelectionIndex() {
return getSelectionModel().getMaxSelectionIndex();
}
*** 2026,2035 ****
--- 2006,2016 ----
*
* @return {@code true} if nothing is selected, else {@code false}
* @see ListSelectionModel#isSelectionEmpty
* @see #clearSelection
*/
+ @BeanProperty(bound = false)
public boolean isSelectionEmpty() {
return getSelectionModel().isSelectionEmpty();
}
*** 2200,2212 ****
*
* @param index the index of the cell to select
* @see ListSelectionModel#setSelectionInterval
* @see #isSelectedIndex
* @see #addListSelectionListener
- * @beaninfo
- * description: The index of the selected cell.
*/
public void setSelectedIndex(int index) {
if (index >= getModel().getSize()) {
return;
}
getSelectionModel().setSelectionInterval(index, index);
--- 2181,2193 ----
*
* @param index the index of the cell to select
* @see ListSelectionModel#setSelectionInterval
* @see #isSelectedIndex
* @see #addListSelectionListener
*/
+ @BeanProperty(bound = false, description
+ = "The index of the selected cell.")
public void setSelectedIndex(int index) {
if (index >= getModel().getSize()) {
return;
}
getSelectionModel().setSelectionInterval(index, index);
*** 2250,2259 ****
--- 2231,2241 ----
* @see #addListSelectionListener
*
* @deprecated As of JDK 1.7, replaced by {@link #getSelectedValuesList()}
*/
@Deprecated
+ @BeanProperty(bound = false)
public Object[] getSelectedValues() {
ListSelectionModel sm = getSelectionModel();
ListModel<E> dm = getModel();
int iMin = sm.getMinSelectionIndex();
*** 2284,2293 ****
--- 2266,2276 ----
* @see #getModel
* @see #addListSelectionListener
*
* @since 1.7
*/
+ @BeanProperty(bound = false)
public List<E> getSelectedValuesList() {
ListSelectionModel sm = getSelectionModel();
ListModel<E> dm = getModel();
int iMin = sm.getMinSelectionIndex();
*** 2336,2345 ****
--- 2319,2329 ----
* @return the first selected value
* @see #getMinSelectionIndex
* @see #getModel
* @see #addListSelectionListener
*/
+ @BeanProperty(bound = false)
public E getSelectedValue() {
int i = getMinSelectionIndex();
return (i == -1) ? null : getModel().getElementAt(i);
}
*** 2425,2434 ****
--- 2409,2419 ----
* @return a dimension containing the size of the viewport needed
* to display {@code visibleRowCount} rows
* @see #getPreferredScrollableViewportSize
* @see #setPrototypeCellValue
*/
+ @BeanProperty(bound = false)
public Dimension getPreferredScrollableViewportSize()
{
if (getLayoutOrientation() != VERTICAL) {
return getPreferredSize();
}
*** 2762,2771 ****
--- 2747,2757 ----
*
* @return whether or not an enclosing viewport should force the list's
* width to match its own
* @see Scrollable#getScrollableTracksViewportWidth
*/
+ @BeanProperty(bound = false)
public boolean getScrollableTracksViewportWidth() {
if (getLayoutOrientation() == HORIZONTAL_WRAP &&
getVisibleRowCount() <= 0) {
return true;
}
*** 2788,2797 ****
--- 2774,2784 ----
*
* @return whether or not an enclosing viewport should force the list's
* height to match its own
* @see Scrollable#getScrollableTracksViewportHeight
*/
+ @BeanProperty(bound = false)
public boolean getScrollableTracksViewportHeight() {
if (getLayoutOrientation() == VERTICAL_WRAP &&
getVisibleRowCount() <= 0) {
return true;
}
*** 2859,2868 ****
--- 2846,2856 ----
* A new {@code AccessibleJList} instance is created if necessary.
*
* @return an {@code AccessibleJList} that serves as the
* {@code AccessibleContext} of this {@code JList}
*/
+ @BeanProperty(bound = false)
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJList();
}
return accessibleContext;