src/java.desktop/share/classes/javax/swing/JList.java

Print this page

        

@@ -20,11 +20,10 @@
  *
  * 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.*;
 

@@ -32,29 +31,29 @@
 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.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>

@@ -269,17 +268,15 @@
  * @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
  */
+@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,16 +510,13 @@
      * 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.
      */
+    @BeanProperty(hidden = true, visualUpdate = true, description
+            = "The UI object that implements the Component's LookAndFeel.")
     public void setUI(ListUI ui) {
         super.setUI(ui);
     }
 
 

@@ -553,10 +547,11 @@
      *
      * @return the string "ListUI"
      * @see JComponent#getUIClassID
      * @see UIDefaults#getUI
      */
+    @BeanProperty(bound = false)
     public String getUIClassID() {
         return uiClassID;
     }
 
 

@@ -638,15 +633,13 @@
      *                          <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.
      */
+    @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,15 +676,13 @@
      *
      * @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.
      */
+    @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,15 +710,13 @@
      *
      * @param height the height 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 height when greater than zero.
      */
+    @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,15 +750,13 @@
      * 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.
      */
+    @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,15 +803,13 @@
      * @see #setSelectionBackground
      * @see #setForeground
      * @see #setBackground
      * @see #setFont
      * @see DefaultListCellRenderer
-     * @beaninfo
-     *       bound: true
-     *   attribute: visualUpdate true
-     * description: The foreground color of selected cells.
      */
+    @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,15 +848,13 @@
      * @see #setSelectionForeground
      * @see #setForeground
      * @see #setBackground
      * @see #setFont
      * @see DefaultListCellRenderer
-     * @beaninfo
-     *       bound: true
-     *   attribute: visualUpdate true
-     * description: The background color of selected cells.
      */
+    @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,16 +901,13 @@
      * @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
      */
+    @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,18 +977,16 @@
      * @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
      */
+    @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,10 +1010,11 @@
      *
      * @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,10 +1041,11 @@
      *
      * @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,15 +1158,13 @@
      * @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
      */
+    @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,10 +1425,11 @@
      * @return the drop location
      * @see #setDropMode
      * @see TransferHandler#canImport(TransferHandler.TransferSupport)
      * @since 1.6
      */
+    @BeanProperty(bound = false)
     public final DropLocation getDropLocation() {
         return dropLocation;
     }
 
     /**

@@ -1662,15 +1641,13 @@
      *                                          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.
      */
+    @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,10 +1835,11 @@
      * @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,14 +1855,13 @@
      * @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.
      */
+    @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,16 +1903,16 @@
      *
      * @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
      */
+    @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,10 +1933,11 @@
      * 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,13 +1945,13 @@
      * 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.
      */
+    @BeanProperty(bound = false, description
+            = "The lead selection index.")
     public int getLeadSelectionIndex() {
         return getSelectionModel().getLeadSelectionIndex();
     }
 
 

@@ -1983,10 +1961,11 @@
      * 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,10 +1975,11 @@
      * 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,10 +2006,11 @@
      *
      * @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,13 +2181,13 @@
      *
      * @param index the index of the cell to select
      * @see ListSelectionModel#setSelectionInterval
      * @see #isSelectedIndex
      * @see #addListSelectionListener
-     * @beaninfo
-     * description: The index of the selected cell.
      */
+    @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,10 +2231,11 @@
      * @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,10 +2266,11 @@
      * @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,10 +2319,11 @@
      * @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,10 +2409,11 @@
      * @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,10 +2747,11 @@
      *
      * @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,10 +2774,11 @@
      *
      * @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,10 +2846,11 @@
      * 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;