JList.java revision 243
243N/A * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * A component that displays a list of objects and allows the user to select 0N/A * one or more items. A separate model, {@code ListModel}, maintains the 0N/A * contents of the list. 0N/A * It's easy to display an array or Vector of objects, using the {@code JList} 0N/A * constructor that automatically builds a read-only {@code ListModel} instance 0N/A * // Create a JList that displays strings from an array 0N/A * String[] data = {"one", "two", "three", "four"}; 0N/A * JList myList = new JList(data); 0N/A * // Create a JList that displays the superclasses of JList.class, by 0N/A * // creating it with a Vector populated with this data 0N/A * Vector superClasses = new Vector(); 0N/A * Class rootClass = javax.swing.JList.class; 0N/A * for(Class cls = rootClass; cls != null; cls = cls.getSuperclass()) { 0N/A * superClasses.addElement(cls); 0N/A * JList myList = new JList(superClasses); 0N/A * // The automatically created model is stored in JList's "model" 0N/A * // property, which you can retrieve 0N/A * ListModel model = myList.getModel(); 0N/A * for(int i = 0; i < model.getSize(); i++) { 0N/A * System.out.println(model.getElementAt(i)); 0N/A * A {@code ListModel} can be supplied directly to a {@code JList} by way of a 0N/A * constructor or the {@code setModel} method. The contents need not be static - 0N/A * the number of items, and the values of items can change over time. A correct 0N/A * {@code ListModel} implementation notifies the set of 0N/A * {@code javax.swing.event.ListDataListener}s that have been added to it, each 0N/A * time a change occurs. These changes are characterized by a 0N/A * {@code javax.swing.event.ListDataEvent}, which identifies the range of list 0N/A * indices that have been modified, added, or removed. {@code JList}'s 0N/A * {@code ListUI} is responsible for keeping the visual representation up to 0N/A * date with changes, by listening to the model. 0N/A * Simple, dynamic-content, {@code JList} applications can use the 0N/A * {@code DefaultListModel} class to maintain list elements. This class 0N/A * implements the {@code ListModel} interface and also provides a 0N/A * <code>java.util.Vector</code>-like API. Applications that need a more 0N/A * custom <code>ListModel</code> implementation may instead wish to subclass 0N/A * {@code AbstractListModel}, which provides basic support for managing and 0N/A * notifying listeners. For example, a read-only implementation of 0N/A * {@code AbstractListModel}: 0N/A * // This list model has about 2^16 elements. Enjoy scrolling. 0N/A * ListModel bigData = new AbstractListModel() { 0N/A * public int getSize() { return Short.MAX_VALUE; } 0N/A * public Object getElementAt(int index) { return "Index " + index; } 0N/A * The selection state of a {@code JList} is managed by another separate 0N/A * model, an instance of {@code ListSelectionModel}. {@code JList} is 0N/A * initialized with a selection model on construction, and also contains 0N/A * methods to query or set this selection model. Additionally, {@code JList} 0N/A * provides convenient methods for easily managing the selection. These methods, 0N/A * such as {@code setSelectedIndex} and {@code getSelectedValue}, are cover 0N/A * methods that take care of the details of interacting with the selection 0N/A * model. By default, {@code JList}'s selection model is configured to allow any 0N/A * combination of items to be selected at a time; selection mode 0N/A * {@code MULTIPLE_INTERVAL_SELECTION}. The selection mode can be changed 0N/A * on the selection model directly, or via {@code JList}'s cover method. 0N/A * Responsibility for updating the selection model in response to user gestures 0N/A * lies with the list's {@code ListUI}. 0N/A * A correct {@code ListSelectionModel} implementation notifies the set of 0N/A * {@code javax.swing.event.ListSelectionListener}s that have been added to it 0N/A * each time a change to the selection occurs. These changes are characterized 0N/A * by a {@code javax.swing.event.ListSelectionEvent}, which identifies the range 0N/A * of the selection change. 0N/A * The preferred way to listen for changes in list selection is to add 0N/A * {@code ListSelectionListener}s directly to the {@code JList}. {@code JList} 0N/A * then takes care of listening to the the selection model and notifying your 0N/A * listeners of change. 0N/A * Responsibility for listening to selection changes in order to keep the list's 0N/A * visual representation up to date lies with the list's {@code ListUI}. 0N/A * <a name="renderer"> 0N/A * Painting of cells in a {@code JList} is handled by a delegate called a 0N/A * cell renderer, installed on the list as the {@code cellRenderer} property. 0N/A * The renderer provides a {@code java.awt.Component} that is used 0N/A * like a "rubber stamp" to paint the cells. Each time a cell needs to be 0N/A * painted, the list's {@code ListUI} asks the cell renderer for the component, 0N/A * moves it into place, and has it paint the contents of the cell by way of its 0N/A * {@code paint} method. A default cell renderer, which uses a {@code JLabel} 0N/A * component to render, is installed by the lists's {@code ListUI}. You can 0N/A * substitute your own renderer using code like this: 0N/A * // Display an icon and a string for each object in the list. 0N/A * class MyCellRenderer extends JLabel implements ListCellRenderer { 0N/A * final static ImageIcon longIcon = new ImageIcon("long.gif"); 0N/A * final static ImageIcon shortIcon = new ImageIcon("short.gif"); 0N/A * // This is the only method defined by ListCellRenderer. 0N/A * // We just reconfigure the JLabel each time we're called. 0N/A * public Component getListCellRendererComponent( 0N/A * JList list, // the list 0N/A * Object value, // value to display 0N/A * int index, // cell index 0N/A * boolean isSelected, // is the cell selected 0N/A * boolean cellHasFocus) // does the cell have focus 0N/A * String s = value.toString(); 0N/A * setIcon((s.length() > 10) ? longIcon : shortIcon); 0N/A * setBackground(list.getSelectionBackground()); 0N/A * setForeground(list.getSelectionForeground()); 0N/A * setBackground(list.getBackground()); 0N/A * setForeground(list.getForeground()); 0N/A * setEnabled(list.isEnabled()); 0N/A * setFont(list.getFont()); 0N/A * myList.setCellRenderer(new MyCellRenderer()); 0N/A * Another job for the cell renderer is in helping to determine sizing 0N/A * information for the list. By default, the list's {@code ListUI} determines 0N/A * the size of cells by asking the cell renderer for its preferred 0N/A * size for each list item. This can be expensive for large lists of items. 0N/A * To avoid these calculations, you can set a {@code fixedCellWidth} and 0N/A * {@code fixedCellHeight} on the list, or have these values calculated 0N/A * automatically based on a single prototype value: 0N/A * <a name="prototype_example"> 0N/A * JList bigDataList = new JList(bigData); 0N/A * // We don't want the JList implementation to compute the width 0N/A * // or height of all of the list cells, so we give it a string 0N/A * // that's as big as we'll need for any cell. It uses this to 0N/A * // compute values for the fixedCellWidth and fixedCellHeight 0N/A * bigDataList.setPrototypeCellValue("Index 1234567890"); 0N/A * {@code JList} doesn't implement scrolling directly. To create a list that 0N/A * scrolls, make it the viewport view of a {@code JScrollPane}. For example: 0N/A * JScrollPane scrollPane = new JScrollPane(myList); 0N/A * // Or in two steps: 0N/A * JScrollPane scrollPane = new JScrollPane(); 0N/A * scrollPane.getViewport().setView(myList); 0N/A * {@code JList} doesn't provide any special handling of double or triple 0N/A * (or N) mouse clicks, but it's easy to add a {@code MouseListener} if you 0N/A * wish to take action on these events. Use the {@code locationToIndex} 0N/A * method to determine what cell was clicked. For example: 0N/A * MouseListener mouseListener = new MouseAdapter() { 0N/A * public void mouseClicked(MouseEvent e) { 0N/A * if (e.getClickCount() == 2) { 0N/A * int index = list.locationToIndex(e.getPoint()); 0N/A * System.out.println("Double clicked on Item " + index); 0N/A * list.addMouseListener(mouseListener); 0N/A * <strong>Warning:</strong> Swing is not thread safe. For more 0N/A * information see <a 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * for further documentation. 0N/A * @see AbstractListModel 0N/A * @see DefaultListModel 0N/A * @see ListSelectionModel 0N/A * @see DefaultListSelectionModel 0N/A * @see ListCellRenderer 0N/A * @see DefaultListCellRenderer 0N/A * attribute: isContainer false 0N/A * description: A component which allows for the selection of one or more objects from a list. 0N/A * @author Hans Muller 0N/A * @see #getUIClassID 0N/A * Indicates a vertical layout of cells, in a single column; 0N/A * the default layout. 0N/A * @see #setLayoutOrientation 0N/A * Indicates a "newspaper style" layout with cells flowing vertically 0N/A * then horizontally. 0N/A * @see #setLayoutOrientation 0N/A * Indicates a "newspaper style" layout with cells flowing horizontally 0N/A * @see #setLayoutOrientation 0N/A * How to lay out the cells; defaults to <code>VERTICAL</code>. 0N/A * The drop mode for this component. 0N/A * The drop location. 0N/A * A subclass of <code>TransferHandler.DropLocation</code> representing 0N/A * a drop location for a <code>JList</code>. 0N/A * @see #getDropLocation 0N/A * Returns the index where dropped data should be placed in the 0N/A * list. Interpretation of the value depends on the drop mode set on 0N/A * the associated component. If the drop mode is either 0N/A * <code>DropMode.USE_SELECTION</code> or <code>DropMode.ON</code>, 0N/A * the return value is an index of a row in the list. If the drop mode is 0N/A * <code>DropMode.INSERT</code>, the return value refers to the index 0N/A * where the data should be inserted. If the drop mode is 0N/A * <code>DropMode.ON_OR_INSERT</code>, the value of 0N/A * <code>isInsert()</code> indicates whether the index is an index 0N/A * of a row, or an insert index. 0N/A * <code>-1</code> indicates that the drop occurred over empty space, 0N/A * and no index could be calculated. 0N/A * @return the drop index 0N/A * Returns whether or not this location represents an insert 0N/A * @return whether or not this is an insert location 0N/A * Returns a string representation of this drop location. 0N/A * This method is intended to be used for debugging purposes, 0N/A * and the content and format of the returned string may vary 0N/A * between implementations. 0N/A * @return a string representation of this drop location 0N/A * Constructs a {@code JList} that displays elements from the specified, 0N/A * {@code non-null}, model. All {@code JList} constructors delegate to 0N/A * This constructor registers the list with the {@code ToolTipManager}, 0N/A * allowing for tooltips to be provided by the cell renderers. 0N/A * @param dataModel the model for the list 0N/A * @exception IllegalArgumentException if the model is {@code null} 0N/A // Register with the ToolTipManager so that tooltips from the 0N/A // renderer show through. 0N/A * Constructs a <code>JList</code> that displays the elements in 0N/A * the specified array. This constructor creates a read-only model 0N/A * for the given array, and then delegates to the constructor that 0N/A * takes a {@code ListModel}. 0N/A * Attempts to pass a {@code null} value to this method results in 0N/A * undefined behavior and, most likely, exceptions. The created model 0N/A * references the given array directly. Attempts to modify the array 0N/A * after constructing the list results in undefined behavior. 0N/A * @param listData the array of Objects to be loaded into the data model, 0N/A * Constructs a <code>JList</code> that displays the elements in 0N/A * the specified <code>Vector</code>. This constructor creates a read-only 0N/A * model for the given {@code Vector}, and then delegates to the constructor 0N/A * that takes a {@code ListModel}. 0N/A * Attempts to pass a {@code null} value to this method results in 0N/A * undefined behavior and, most likely, exceptions. The created model 0N/A * references the given {@code Vector} directly. Attempts to modify the 0N/A * {@code Vector} after constructing the list results in undefined behavior. 0N/A * @param listData the <code>Vector</code> to be loaded into the 0N/A * data model, {@code non-null} 0N/A * Constructs a <code>JList</code> with an empty, read-only, model. 0N/A * Returns the {@code ListUI}, the look and feel object that 0N/A * renders this component. 0N/A * @return the <code>ListUI</code> object that renders this component 0N/A * Sets the {@code ListUI}, the look and feel object that 0N/A * renders this component. 0N/A * @param ui the <code>ListUI</code> object 0N/A * @see UIDefaults#getUI 0N/A * attribute: visualUpdate true 0N/A * description: The UI object that implements the Component's LookAndFeel. 0N/A * Resets the {@code ListUI} property by setting it to the value provided 0N/A * by the current look and feel. If the current cell renderer was installed 0N/A * by the developer (rather than the look and feel itself), this also causes 0N/A * the cell renderer and its children to be updated, by calling 0N/A * {@code SwingUtilities.updateComponentTreeUI} on it. 0N/A * @see UIManager#getUI 0N/A * @see SwingUtilities#updateComponentTreeUI 0N/A * Returns {@code "ListUI"}, the <code>UIDefaults</code> key used to look 0N/A * up the name of the {@code javax.swing.plaf.ListUI} class that defines 0N/A * the look and feel for this component. 0N/A * @return the string "ListUI" 0N/A * @see JComponent#getUIClassID 0N/A * @see UIDefaults#getUI 0N/A /* -----private----- 0N/A * This method is called by setPrototypeCellValue and setCellRenderer 0N/A * to update the fixedCellWidth and fixedCellHeight properties from the 0N/A * current value of prototypeCellValue (if it's non null). 0N/A * This method sets fixedCellWidth and fixedCellHeight but does <b>not</b> 0N/A * generate PropertyChangeEvents for them. 0N/A * @see #setPrototypeCellValue 0N/A * @see #setCellRenderer 0N/A /* The ListUI implementation will add Component c to its private 0N/A * CellRendererPane however we can't assume that's already 0N/A * been done here. So we temporarily set the one "inherited" 0N/A * property that may affect the renderer components preferred size: 0N/A * Returns the "prototypical" cell value -- a value used to calculate a 0N/A * fixed width and height for cells. This can be {@code null} if there 0N/A * @return the value of the {@code prototypeCellValue} property 0N/A * @see #setPrototypeCellValue 0N/A * Sets the {@code prototypeCellValue} property, and then (if the new value 0N/A * is {@code non-null}), computes the {@code fixedCellWidth} and 0N/A * {@code fixedCellHeight} properties by requesting the cell renderer 0N/A * component for the given value (and index 0) from the cell renderer, and 0N/A * using that component's preferred size. 0N/A * This method is useful when the list is too long to allow the 0N/A * {@code ListUI} to compute the width/height of each cell, and there is a 0N/A * single cell value that is known to occupy as much space as any of the 0N/A * others, a so-called prototype. 0N/A * While all three of the {@code prototypeCellValue}, 0N/A * {@code fixedCellHeight}, and {@code fixedCellWidth} properties may be 0N/A * modified by this method, {@code PropertyChangeEvent} notifications are 0N/A * only sent when the {@code prototypeCellValue} property changes. 0N/A * To see an example which sets this property, see the 0N/A * <a href="#prototype_example">class description</a> above. 0N/A * The default value of this property is <code>null</code>. 0N/A * This is a JavaBeans bound property. 0N/A * @param prototypeCellValue the value on which to base 0N/A * <code>fixedCellWidth</code> and 0N/A * <code>fixedCellHeight</code> 0N/A * @see #getPrototypeCellValue 0N/A * @see #setFixedCellWidth 0N/A * @see #setFixedCellHeight 0N/A * @see JComponent#addPropertyChangeListener 0N/A * attribute: visualUpdate true 0N/A * description: The cell prototype value, used to compute cell width and height. 0N/A /* If the prototypeCellValue has changed and is non-null, 0N/A * then recompute fixedCellWidth and fixedCellHeight. 0N/A * Returns the value of the {@code fixedCellWidth} property. 0N/A * @return the fixed cell width 0N/A * @see #setFixedCellWidth 0N/A * Sets a fixed value to be used for the width of every cell in the list. 0N/A * If {@code width} is -1, cell widths are computed in the {@code ListUI} 0N/A * by applying <code>getPreferredSize</code> to the cell renderer component 0N/A * for each list element. 0N/A * The default value of this property is {@code -1}. 0N/A * This is a JavaBeans bound property. 0N/A * @param width the width to be used for all cells in the list 0N/A * @see #setPrototypeCellValue 0N/A * @see #setFixedCellWidth 0N/A * @see JComponent#addPropertyChangeListener 0N/A * attribute: visualUpdate true 0N/A * description: Defines a fixed cell width when greater than zero. 0N/A * Returns the value of the {@code fixedCellHeight} property. 0N/A * @return the fixed cell height 0N/A * @see #setFixedCellHeight 0N/A * Sets a fixed value to be used for the height of every cell in the list. 0N/A * If {@code height} is -1, cell heights are computed in the {@code ListUI} 0N/A * by applying <code>getPreferredSize</code> to the cell renderer component 0N/A * for each list element. 0N/A * The default value of this property is {@code -1}. 0N/A * This is a JavaBeans bound property. 0N/A * @param height the height to be used for for all cells in the list 0N/A * @see #setPrototypeCellValue 0N/A * @see #setFixedCellWidth 0N/A * @see JComponent#addPropertyChangeListener 0N/A * attribute: visualUpdate true 0N/A * description: Defines a fixed cell height when greater than zero. 0N/A * Returns the object responsible for painting list items. 0N/A * @return the value of the {@code cellRenderer} property 0N/A * @see #setCellRenderer 0N/A * Sets the delegate that is used to paint each cell in the list. 0N/A * The job of a cell renderer is discussed in detail in the 0N/A * <a href="#renderer">class level documentation</a>. 0N/A * If the {@code prototypeCellValue} property is {@code non-null}, 0N/A * setting the cell renderer also causes the {@code fixedCellWidth} and 0N/A * {@code fixedCellHeight} properties to be re-calculated. Only one 0N/A * <code>PropertyChangeEvent</code> is generated however - 0N/A * for the <code>cellRenderer</code> property. 0N/A * The default value of this property is provided by the {@code ListUI} 0N/A * delegate, i.e. by the look and feel implementation. 0N/A * This is a JavaBeans bound property. 0N/A * @param cellRenderer the <code>ListCellRenderer</code> 0N/A * that paints list cells 0N/A * @see #getCellRenderer 0N/A * attribute: visualUpdate true 0N/A * description: The component used to draw the cells. 0N/A /* If the cellRenderer has changed and prototypeCellValue 0N/A * was set, then recompute fixedCellWidth and fixedCellHeight. 0N/A * Returns the color used to draw the foreground of selected items. 0N/A * {@code DefaultListCellRenderer} uses this color to draw the foreground 0N/A * of items in the selected state, as do the renderers installed by most 0N/A * {@code ListUI} implementations. 0N/A * @return the color to draw the foreground of selected items 0N/A * @see #setSelectionForeground 0N/A * @see DefaultListCellRenderer 0N/A * Sets the color used to draw the foreground of selected items, which 0N/A * cell renderers can use to render text and graphics. 0N/A * {@code DefaultListCellRenderer} uses this color to draw the foreground 0N/A * of items in the selected state, as do the renderers installed by most 0N/A * {@code ListUI} implementations. 0N/A * The default value of this property is defined by the look and feel 0N/A * This is a JavaBeans bound property. 0N/A * @param selectionForeground the {@code Color} to use in the foreground 0N/A * for selected list items 0N/A * @see #getSelectionForeground 0N/A * @see #setSelectionBackground 0N/A * @see #setForeground 0N/A * @see #setBackground 0N/A * @see DefaultListCellRenderer 0N/A * attribute: visualUpdate true 0N/A * description: The foreground color of selected cells. 0N/A * Returns the color used to draw the background of selected items. 0N/A * {@code DefaultListCellRenderer} uses this color to draw the background 0N/A * of items in the selected state, as do the renderers installed by most 0N/A * {@code ListUI} implementations. 0N/A * @return the color to draw the background of selected items 0N/A * @see #setSelectionBackground 0N/A * @see DefaultListCellRenderer 0N/A * Sets the color used to draw the background of selected items, which 0N/A * cell renderers can use fill selected cells. 0N/A * {@code DefaultListCellRenderer} uses this color to fill the background 0N/A * of items in the selected state, as do the renderers installed by most 0N/A * {@code ListUI} implementations. 0N/A * The default value of this property is defined by the look 0N/A * and feel implementation. 0N/A * This is a JavaBeans bound property. 0N/A * @param selectionBackground the {@code Color} to use for the 0N/A * background of selected cells 0N/A * @see #getSelectionBackground 0N/A * @see #setSelectionForeground 0N/A * @see #setForeground 0N/A * @see #setBackground 0N/A * @see DefaultListCellRenderer 0N/A * attribute: visualUpdate true 0N/A * description: The background color of selected cells. 0N/A * Returns the value of the {@code visibleRowCount} property. See the 0N/A * documentation for {@link #setVisibleRowCount} for details on how to 0N/A * interpret this value. 0N/A * @return the value of the {@code visibleRowCount} property. 0N/A * @see #setVisibleRowCount 0N/A * Sets the {@code visibleRowCount} property, which has different meanings 0N/A * depending on the layout orientation: For a {@code VERTICAL} layout 0N/A * orientation, this sets the preferred number of rows to display without 0N/A * requiring scrolling; for other orientations, it affects the wrapping of 0N/A * In {@code VERTICAL} orientation:<br> 0N/A * Setting this property affects the return value of the 0N/A * {@link #getPreferredScrollableViewportSize} method, which is used to 0N/A * calculate the preferred size of an enclosing viewport. See that method's 0N/A * documentation for more details. 0N/A * In {@code HORIZONTAL_WRAP} and {@code VERTICAL_WRAP} orientations:<br> 0N/A * This affects how cells are wrapped. See the documentation of 0N/A * {@link #setLayoutOrientation} for more details. 0N/A * The default value of this property is {@code 8}. 0N/A * Calling this method with a negative value results in the property 0N/A * being set to {@code 0}. 0N/A * This is a JavaBeans bound property. 0N/A * @param visibleRowCount an integer specifying the preferred number of 0N/A * rows to display without requiring scrolling 0N/A * @see #getVisibleRowCount 0N/A * @see #getPreferredScrollableViewportSize 0N/A * @see #setLayoutOrientation 0N/A * @see JComponent#getVisibleRect 0N/A * attribute: visualUpdate true 0N/A * description: The preferred number of rows to display without 0N/A * requiring scrolling 0N/A * Returns the layout orientation property for the list: {@code VERTICAL} 0N/A * if the layout is a single column of cells, {@code VERTICAL_WRAP} if the 0N/A * layout is "newspaper style" with the content flowing vertically then 0N/A * horizontally, or {@code HORIZONTAL_WRAP} if the layout is "newspaper 0N/A * style" with the content flowing horizontally then vertically. 0N/A * @return the value of the {@code layoutOrientation} property 0N/A * @see #setLayoutOrientation 0N/A * Defines the way list cells are layed out. Consider a {@code JList} 0N/A * with five cells. Cells can be layed out in one of the following ways: 0N/A * HORIZONTAL_WRAP: 0 1 2 0N/A * VERTICAL_WRAP: 0 3 0N/A * A description of these layouts follows: 0N/A * summary="Describes layouts VERTICAL, HORIZONTAL_WRAP, and VERTICAL_WRAP"> 0N/A * <tr><th><p align="left">Value</p></th><th><p align="left">Description</p></th></tr> 0N/A * <tr><td><code>VERTICAL</code> 0N/A * <td>Cells are layed out vertically in a single column. 0N/A * <tr><td><code>HORIZONTAL_WRAP</code> 0N/A * <td>Cells are layed out horizontally, wrapping to a new row as 0N/A * necessary. If the {@code visibleRowCount} property is less than 0N/A * or equal to zero, wrapping is determined by the width of the 0N/A * list; otherwise wrapping is done in such a way as to ensure 0N/A * {@code visibleRowCount} rows in the list. 0N/A * <tr><td><code>VERTICAL_WRAP</code> 0N/A * <td>Cells are layed out vertically, wrapping to a new column as 0N/A * necessary. If the {@code visibleRowCount} property is less than 0N/A * or equal to zero, wrapping is determined by the height of the 0N/A * list; otherwise wrapping is done at {@code visibleRowCount} rows. 0N/A * The default value of this property is <code>VERTICAL</code>. 0N/A * @param layoutOrientation the new layout orientation, one of: 0N/A * {@code VERTICAL}, {@code HORIZONTAL_WRAP} or {@code VERTICAL_WRAP} 0N/A * @see #getLayoutOrientation 0N/A * @see #setVisibleRowCount 0N/A * @see #getScrollableTracksViewportHeight 0N/A * @see #getScrollableTracksViewportWidth 0N/A * @throws IllegalArgumentException if {@code layoutOrientation} isn't one of the 0N/A * attribute: visualUpdate true 0N/A * description: Defines the way list cells are layed out. 0N/A * enum: VERTICAL JList.VERTICAL 0N/A * HORIZONTAL_WRAP JList.HORIZONTAL_WRAP 0N/A * VERTICAL_WRAP JList.VERTICAL_WRAP 0N/A * Returns the smallest list index that is currently visible. 0N/A * In a left-to-right {@code componentOrientation}, the first visible 0N/A * cell is found closest to the list's upper-left corner. In right-to-left 0N/A * orientation, it is found closest to the upper-right corner. 0N/A * If nothing is visible or the list is empty, {@code -1} is returned. 0N/A * Note that the returned cell may only be partially visible. 0N/A * @return the index of the first visible cell 0N/A * @see #getLastVisibleIndex 0N/A * @see JComponent#getVisibleRect 0N/A * Returns the largest list index that is currently visible. 0N/A * If nothing is visible or the list is empty, {@code -1} is returned. 0N/A * Note that the returned cell may only be partially visible. 0N/A * @return the index of the last visible cell 0N/A * @see #getFirstVisibleIndex 0N/A * @see JComponent#getVisibleRect 0N/A // Try the top left(LTR) or top right(RTL) corner, and 0N/A // then go across checking each cell for HORIZONTAL_WRAP. 0N/A // Try the lower left corner, and then go across checking 0N/A // each cell for other list layout orientation. 0N/A // Past visible region, bail. 0N/A // Past visible region, bail. 0N/A * Scrolls the list within an enclosing viewport to make the specified 0N/A * cell completely visible. This calls {@code scrollRectToVisible} with 0N/A * the bounds of the specified cell. For this method to work, the 0N/A * {@code JList} must be within a <code>JViewport</code>. 0N/A * If the given index is outside the list's range of cells, this method 0N/A * results in nothing. 0N/A * @param index the index of the cell to make visible 0N/A * @see JComponent#scrollRectToVisible 0N/A * @see #getVisibleRect 0N/A * Turns on or off automatic drag handling. In order to enable automatic 0N/A * drag handling, this property should be set to {@code true}, and the 0N/A * list's {@code TransferHandler} needs to be {@code non-null}. 0N/A * The default value of the {@code dragEnabled} property is {@code false}. 0N/A * The job of honoring this property, and recognizing a user drag gesture, 0N/A * lies with the look and feel implementation, and in particular, the list's 0N/A * {@code ListUI}. When automatic drag handling is enabled, most look and 0N/A * feels (including those that subclass {@code BasicLookAndFeel}) begin a 0N/A * drag and drop operation whenever the user presses the mouse button over 0N/A * an item and then moves the mouse a few pixels. Setting this property to 0N/A * {@code true} can therefore have a subtle effect on how selections behave. 0N/A * If a look and feel is used that ignores this property, you can still 0N/A * begin a drag and drop operation by calling {@code exportAsDrag} on the 0N/A * list's {@code TransferHandler}. 0N/A * @param b whether or not to enable automatic drag handling 0N/A * @exception HeadlessException if 0N/A * <code>b</code> is <code>true</code> and 0N/A * <code>GraphicsEnvironment.isHeadless()</code> 0N/A * returns <code>true</code> 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A * @see #getDragEnabled 0N/A * @see #setTransferHandler 0N/A * @see TransferHandler 0N/A * description: determines whether automatic drag handling is enabled 0N/A * Returns whether or not automatic drag handling is enabled. 0N/A * @return the value of the {@code dragEnabled} property 0N/A * @see #setDragEnabled 0N/A * Sets the drop mode for this component. For backward compatibility, 0N/A * the default for this property is <code>DropMode.USE_SELECTION</code>. 0N/A * Usage of one of the other modes is recommended, however, for an 0N/A * improved user experience. <code>DropMode.ON</code>, for instance, 0N/A * offers similar behavior of showing items as selected, but does so without 0N/A * affecting the actual selection in the list. 0N/A * <code>JList</code> supports the following drop modes: 0N/A * <li><code>DropMode.USE_SELECTION</code></li> 0N/A * <li><code>DropMode.ON</code></li> 0N/A * <li><code>DropMode.INSERT</code></li> 0N/A * <li><code>DropMode.ON_OR_INSERT</code></li> 0N/A * The drop mode is only meaningful if this component has a 0N/A * <code>TransferHandler</code> that accepts drops. 0N/A * @param dropMode the drop mode to use 0N/A * @throws IllegalArgumentException if the drop mode is unsupported 0N/A * or <code>null</code> 0N/A * @see #getDropLocation 0N/A * @see #setTransferHandler 0N/A * @see TransferHandler 0N/A * Returns the drop mode for this component. 0N/A * @return the drop mode for this component 0N/A * Calculates a drop location in this component, representing where a 0N/A * drop at the given point should insert data. 0N/A * @param p the point to calculate a drop location for 0N/A * @return the drop location, or <code>null</code> 0N/A // special case for below all cells 0N/A // special case for below all cells 0N/A assert false :
"Unexpected drop mode";
0N/A * Called to set or clear the drop location during a DnD operation. 0N/A * In some cases, the component may need to use it's internal selection 0N/A * temporarily to indicate the drop location. To help facilitate this, 0N/A * this method returns and accepts as a parameter a state object. 0N/A * This state object can be used to store, and later restore, the selection 0N/A * state. Whatever this method returns will be passed back to it in 0N/A * future calls, as the state parameter. If it wants the DnD system to 0N/A * continue storing the same state, it must pass it back every time. 0N/A * Here's how this is used: 0N/A * Let's say that on the first call to this method the component decides 0N/A * to save some state (because it is about to use the selection to show 0N/A * a drop index). It can return a state object to the caller encapsulating 0N/A * any saved selection state. On a second call, let's say the drop location 0N/A * is being changed to something else. The component doesn't need to 0N/A * restore anything yet, so it simply passes back the same state object 0N/A * to have the DnD system continue storing it. Finally, let's say this 0N/A * method is messaged with <code>null</code>. This means DnD 0N/A * is finished with this component for now, meaning it should restore 0N/A * state. At this point, it can use the state parameter to restore 0N/A * said state, and of course return <code>null</code> since there's 0N/A * no longer anything to store. 0N/A * @param location the drop location (as calculated by 0N/A * <code>dropLocationForPoint</code>) or <code>null</code> 0N/A * if there's no longer a valid drop location 0N/A * @param state the state object saved earlier for this component, 0N/A * or <code>null</code> 0N/A * @param forDrop whether or not the method is being called because an 0N/A * actual drop occurred 0N/A * @return any saved state for this component, or <code>null</code> if none 0N/A * Returns the location that this component should visually indicate 0N/A * as the drop location during a DnD operation over the component, 0N/A * or {@code null} if no location is to currently be shown. 0N/A * This method is not meant for querying the drop location 0N/A * from a {@code TransferHandler}, as the drop location is only 0N/A * set after the {@code TransferHandler}'s <code>canImport</code> 0N/A * has returned and has allowed for the location to be shown. 0N/A * When this property changes, a property change event with 0N/A * name "dropLocation" is fired by the component. 0N/A * By default, responsibility for listening for changes to this property 0N/A * and indicating the drop location visually lies with the list's 0N/A * {@code ListUI}, which may paint it directly and/or install a cell 0N/A * renderer to do so. Developers wishing to implement custom drop location 0N/A * painting and/or replace the default cell renderer, may need to honor 0N/A * @return the drop location 0N/A * @see TransferHandler#canImport(TransferHandler.TransferSupport) 0N/A * Returns the next list element whose {@code toString} value 0N/A * starts with the given prefix. 0N/A * @param prefix the string to test for a match 0N/A * @param startIndex the index for starting the search 0N/A * @param bias the search direction, either 0N/A * Position.Bias.Forward or Position.Bias.Backward. 0N/A * @return the index of the next list element that 0N/A * starts with the prefix; otherwise {@code -1} 0N/A * @exception IllegalArgumentException if prefix is {@code null} 0N/A * or startIndex is out of bounds 0N/A // start search from the next element after the selected element 0N/A * Returns the tooltip text to be used for the given event. This overrides 0N/A * {@code JComponent}'s {@code getToolTipText} to first check the cell 0N/A * renderer component for the cell over which the event occurred, returning 0N/A * its tooltip text, if any. This implementation allows you to specify 0N/A * tooltip text on the cell level, by using {@code setToolTipText} on your 0N/A * cell renderer component. 0N/A * <bold>Note:</bold> For <code>JList</code> to properly display the 0N/A * tooltips of its renderers in this manner, <code>JList</code> must be a 0N/A * registered component with the <code>ToolTipManager</code>. This registration 0N/A * is done automatically in the constructor. However, if at a later point 0N/A * <code>JList</code> is unregistered, by way of a call to 0N/A * {@code setToolTipText(null)}, tips from the renderers will no longer display. 0N/A * @param event the {@code MouseEvent} to fetch the tooltip text for 0N/A * @see JComponent#setToolTipText 0N/A * @see JComponent#getToolTipText 0N/A * --- ListUI Delegations --- 0N/A * Returns the cell index closest to the given location in the list's 0N/A * coordinate system. To determine if the cell actually contains the 0N/A * specified location, compare the point against the cell's bounds, 0N/A * as provided by {@code getCellBounds}. This method returns {@code -1} 0N/A * if the model is empty 0N/A * This is a cover method that delegates to the method of the same name 0N/A * in the list's {@code ListUI}. It returns {@code -1} if the list has 0N/A * no {@code ListUI}. 0N/A * @param location the coordinates of the point 0N/A * @return the cell index closest to the given location, or {@code -1} 0N/A * Returns the origin of the specified item in the list's coordinate 0N/A * system. This method returns {@code null} if the index isn't valid. 0N/A * This is a cover method that delegates to the method of the same name 0N/A * in the list's {@code ListUI}. It returns {@code null} if the list has 0N/A * no {@code ListUI}. 0N/A * @param index the cell index 0N/A * @return the origin of the cell, or {@code null} 0N/A * Returns the bounding rectangle, in the list's coordinate system, 0N/A * for the range of cells specified by the two indices. 0N/A * These indices can be supplied in any order. 0N/A * If the smaller index is outside the list's range of cells, this method 0N/A * returns {@code null}. If the smaller index is valid, but the larger 0N/A * index is outside the list's range, the bounds of just the first index 0N/A * is returned. Otherwise, the bounds of the valid range is returned. 0N/A * This is a cover method that delegates to the method of the same name 0N/A * in the list's {@code ListUI}. It returns {@code null} if the list has 0N/A * no {@code ListUI}. 0N/A * @param index0 the first index in the range 0N/A * @param index1 the second index in the range 0N/A * @return the bounding rectangle for the range of cells, or {@code null} 0N/A * --- ListModel Support --- 0N/A * Returns the data model that holds the list of items displayed 0N/A * by the <code>JList</code> component. 0N/A * @return the <code>ListModel</code> that provides the displayed 0N/A * Sets the model that represents the contents or "value" of the 0N/A * list, notifies property change listeners, and then clears the 0N/A * This is a JavaBeans bound property. 0N/A * @param model the <code>ListModel</code> that provides the 0N/A * list of items for display 0N/A * @exception IllegalArgumentException if <code>model</code> is 0N/A * @see #clearSelection 0N/A * attribute: visualUpdate true 0N/A * description: The object that contains the data to be drawn by this JList. 0N/A * Constructs a read-only <code>ListModel</code> from an array of objects, 0N/A * and calls {@code setModel} with this model. 0N/A * Attempts to pass a {@code null} value to this method results in 0N/A * undefined behavior and, most likely, exceptions. The created model 0N/A * references the given array directly. Attempts to modify the array 0N/A * after invoking this method results in undefined behavior. 0N/A * @param listData an array of {@code Objects} containing the items to 0N/A * display in the list 0N/A * Constructs a read-only <code>ListModel</code> from a <code>Vector</code> 0N/A * and calls {@code setModel} with this model. 0N/A * Attempts to pass a {@code null} value to this method results in 0N/A * undefined behavior and, most likely, exceptions. The created model 0N/A * references the given {@code Vector} directly. Attempts to modify the 0N/A * {@code Vector} after invoking this method results in undefined behavior. 0N/A * @param listData a <code>Vector</code> containing the items to 0N/A * display in the list 0N/A * --- ListSelectionModel delegations and extensions --- 0N/A * Returns an instance of {@code DefaultListSelectionModel}; called 0N/A * during construction to initialize the list's selection model 0N/A * @return a {@code DefaultListSelecitonModel}, used to initialize 0N/A * the list's selection model property during construction 0N/A * @see #setSelectionModel 0N/A * @see DefaultListSelectionModel 0N/A * Returns the current selection model. The selection model maintains the 0N/A * selection state of the list. See the class level documentation for more 0N/A * @return the <code>ListSelectionModel</code> that maintains the 0N/A * @see #setSelectionModel 0N/A * @see ListSelectionModel 0N/A * Notifies {@code ListSelectionListener}s added directly to the list 0N/A * of selection changes made to the selection model. {@code JList} 0N/A * listens for changes made to the selection in the selection model, 0N/A * and forwards notification to listeners added to the list directly, 0N/A * by calling this method. 0N/A * This method constructs a {@code ListSelectionEvent} with this list 0N/A * as the source, and the specified arguments, and sends it to the 0N/A * registered {@code ListSelectionListeners}. 0N/A * @param firstIndex the first index in the range, {@code <= lastIndex} 0N/A * @param lastIndex the last index in the range, {@code >= firstIndex} 0N/A * @param isAdjusting whether or not this is one in a series of 0N/A * multiple events, where changes are still being made 0N/A * @see #addListSelectionListener 0N/A * @see #removeListSelectionListener 0N/A * @see javax.swing.event.ListSelectionEvent 0N/A * @see EventListenerList 0N/A /* A ListSelectionListener that forwards ListSelectionEvents from 0N/A * the selectionModel to the JList ListSelectionListeners. The 0N/A * forwarded events only differ from the originals in that their 0N/A * source is the JList instead of the selectionModel itself. 0N/A * Adds a listener to the list, to be notified each time a change to the 0N/A * selection occurs; the preferred way of listening for selection state 0N/A * changes. {@code JList} takes care of listening for selection state 0N/A * changes in the selection model, and notifies the given listener of 0N/A * each change. {@code ListSelectionEvent}s sent to the listener have a 0N/A * {@code source} property set to this list. 0N/A * @param listener the {@code ListSelectionListener} to add 0N/A * @see #getSelectionModel 0N/A * @see #getListSelectionListeners 0N/A * Removes a selection listener from the list. 0N/A * @param listener the {@code ListSelectionListener} to remove 0N/A * @see #addListSelectionListener 0N/A * @see #getSelectionModel 0N/A * Returns an array of all the {@code ListSelectionListener}s added 0N/A * to this {@code JList} by way of {@code addListSelectionListener}. 0N/A * @return all of the {@code ListSelectionListener}s on this list, or 0N/A * an empty array if no listeners have been added 0N/A * @see #addListSelectionListener 0N/A * Sets the <code>selectionModel</code> for the list to a 0N/A * non-<code>null</code> <code>ListSelectionModel</code> 0N/A * implementation. The selection model handles the task of making single 0N/A * selections, selections of contiguous ranges, and non-contiguous 0N/A * This is a JavaBeans bound property. 0N/A * @param selectionModel the <code>ListSelectionModel</code> that 0N/A * implements the selections 0N/A * @exception IllegalArgumentException if <code>selectionModel</code> 0N/A * is <code>null</code> 0N/A * @see #getSelectionModel 0N/A * description: The selection model, recording which cells are selected. 0N/A /* Remove the forwarding ListSelectionListener from the old 0N/A * selectionModel, and add it to the new one, if necessary. 0N/A * Sets the selection mode for the list. This is a cover method that sets 0N/A * the selection mode directly on the selection model. 0N/A * The following list describes the accepted selection modes: 0N/A * <li>{@code ListSelectionModel.SINGLE_SELECTION} - 0N/A * Only one list index can be selected at a time. In this mode, 0N/A * {@code setSelectionInterval} and {@code addSelectionInterval} are 0N/A * equivalent, both replacing the current selection with the index 0N/A * represented by the second argument (the "lead"). 0N/A * <li>{@code ListSelectionModel.SINGLE_INTERVAL_SELECTION} - 0N/A * Only one contiguous interval can be selected at a time. 0N/A * In this mode, {@code addSelectionInterval} behaves like 0N/A * {@code setSelectionInterval} (replacing the current selection}, 0N/A * unless the given interval is immediately adjacent to or overlaps 0N/A * the existing selection, and can be used to grow the selection. 0N/A * <li>{@code ListSelectionModel.MULTIPLE_INTERVAL_SELECTION} - 0N/A * In this mode, there's no restriction on what can be selected. 0N/A * This mode is the default. 0N/A * @param selectionMode the selection mode 0N/A * @see #getSelectionMode 0N/A * @throws IllegalArgumentException if the selection mode isn't 0N/A * one of those allowed 0N/A * description: The selection mode. 0N/A * enum: SINGLE_SELECTION ListSelectionModel.SINGLE_SELECTION 0N/A * SINGLE_INTERVAL_SELECTION ListSelectionModel.SINGLE_INTERVAL_SELECTION 0N/A * MULTIPLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION 0N/A * Returns the current selection mode for the list. This is a cover 0N/A * method that delegates to the method of the same name on the 0N/A * list's selection model. 0N/A * @return the current selection mode 0N/A * @see #setSelectionMode 0N/A * Returns the anchor selection index. This is a cover method that 0N/A * delegates to the method of the same name on the list's selection model. 0N/A * @return the anchor selection index 0N/A * @see ListSelectionModel#getAnchorSelectionIndex 0N/A * Returns the lead selection index. This is a cover method that 0N/A * delegates to the method of the same name on the list's selection model. 0N/A * @return the lead selection index 0N/A * @see ListSelectionModel#getLeadSelectionIndex 0N/A * description: The lead selection index. 0N/A * Returns the smallest selected cell index, or {@code -1} if the selection 0N/A * is empty. This is a cover method that delegates to the method of the same 0N/A * name on the list's selection model. 0N/A * @return the smallest selected cell index, or {@code -1} 0N/A * @see ListSelectionModel#getMinSelectionIndex 0N/A * Returns the largest selected cell index, or {@code -1} if the selection 0N/A * is empty. This is a cover method that delegates to the method of the same 0N/A * name on the list's selection model. 0N/A * @return the largest selected cell index 0N/A * @see ListSelectionModel#getMaxSelectionIndex 0N/A * Returns {@code true} if the specified index is selected, 0N/A * else {@code false}. This is a cover method that delegates to the method 0N/A * of the same name on the list's selection model. 0N/A * @param index index to be queried for selection state 0N/A * @return {@code true} if the specified index is selected, 0N/A * else {@code false} 0N/A * @see ListSelectionModel#isSelectedIndex 0N/A * @see #setSelectedIndex 0N/A * Returns {@code true} if nothing is selected, else {@code false}. 0N/A * This is a cover method that delegates to the method of the same 0N/A * name on the list's selection model. 0N/A * @return {@code true} if nothing is selected, else {@code false} 0N/A * @see ListSelectionModel#isSelectionEmpty 0N/A * @see #clearSelection 0N/A * Clears the selection; after calling this method, {@code isSelectionEmpty} 0N/A * will return {@code true}. This is a cover method that delegates to the 0N/A * method of the same name on the list's selection model. 0N/A * @see ListSelectionModel#clearSelection 0N/A * @see #isSelectionEmpty 0N/A * Selects the specified interval. Both {@code anchor} and {@code lead} 0N/A * indices are included. {@code anchor} doesn't have to be less than or 0N/A * equal to {@code lead}. This is a cover method that delegates to the 0N/A * method of the same name on the list's selection model. 0N/A * Refer to the documentation of the selection model class being used 0N/A * for details on how values less than {@code 0} are handled. 0N/A * @param anchor the first index to select 0N/A * @param lead the last index to select 0N/A * @see ListSelectionModel#setSelectionInterval 0N/A * @see DefaultListSelectionModel#setSelectionInterval 0N/A * @see #createSelectionModel 0N/A * @see #addSelectionInterval 0N/A * @see #removeSelectionInterval 0N/A * Sets the selection to be the union of the specified interval with current 0N/A * selection. Both the {@code anchor} and {@code lead} indices are 0N/A * included. {@code anchor} doesn't have to be less than or 0N/A * equal to {@code lead}. This is a cover method that delegates to the 0N/A * method of the same name on the list's selection model. 0N/A * Refer to the documentation of the selection model class being used 0N/A * for details on how values less than {@code 0} are handled. 0N/A * @param anchor the first index to add to the selection 0N/A * @param lead the last index to add to the selection 0N/A * @see ListSelectionModel#addSelectionInterval 0N/A * @see DefaultListSelectionModel#addSelectionInterval 0N/A * @see #createSelectionModel 0N/A * @see #setSelectionInterval 0N/A * @see #removeSelectionInterval 0N/A * Sets the selection to be the set difference of the specified interval 0N/A * and the current selection. Both the {@code index0} and {@code index1} 0N/A * indices are removed. {@code index0} doesn't have to be less than or 0N/A * equal to {@code index1}. This is a cover method that delegates to the 0N/A * method of the same name on the list's selection model. 0N/A * Refer to the documentation of the selection model class being used 0N/A * for details on how values less than {@code 0} are handled. 0N/A * @param index0 the first index to remove from the selection 0N/A * @param index1 the last index to remove from the selection 0N/A * @see ListSelectionModel#removeSelectionInterval 0N/A * @see DefaultListSelectionModel#removeSelectionInterval 0N/A * @see #createSelectionModel 0N/A * @see #setSelectionInterval 0N/A * @see #addSelectionInterval 0N/A * Sets the selection model's {@code valueIsAdjusting} property. When 0N/A * {@code true}, upcoming changes to selection should be considered part 0N/A * of a single change. This property is used internally and developers 0N/A * typically need not call this method. For example, when the model is being 0N/A * updated in response to a user drag, the value of the property is set 0N/A * to {@code true} when the drag is initiated and set to {@code false} 0N/A * when the drag is finished. This allows listeners to update only 0N/A * when a change has been finalized, rather than handling all of the 0N/A * intermediate values. 0N/A * You may want to use this directly if making a series of changes 0N/A * that should be considered part of a single change. 0N/A * This is a cover method that delegates to the method of the same name on 0N/A * the list's selection model. See the documentation for 0N/A * {@link javax.swing.ListSelectionModel#setValueIsAdjusting} for 0N/A * @param b the new value for the property 0N/A * @see ListSelectionModel#setValueIsAdjusting 0N/A * @see javax.swing.event.ListSelectionEvent#getValueIsAdjusting 0N/A * @see #getValueIsAdjusting 0N/A * Returns the value of the selection model's {@code isAdjusting} property. 0N/A * This is a cover method that delegates to the method of the same name on 0N/A * the list's selection model. 0N/A * @return the value of the selection model's {@code isAdjusting} property. 0N/A * @see #setValueIsAdjusting 0N/A * @see ListSelectionModel#getValueIsAdjusting 0N/A * Returns an array of all of the selected indices, in increasing 0N/A * @return all of the selected indices, in increasing order, 0N/A * or an empty array if nothing is selected 0N/A * @see #removeSelectionInterval 0N/A * @see #addListSelectionListener 0N/A * Selects a single cell. Does nothing if the given index is greater 0N/A * than or equal to the model size. This is a convenience method that uses 0N/A * {@code setSelectionInterval} on the selection model. Refer to the 0N/A * documentation for the selection model class being used for details on 0N/A * how values less than {@code 0} are handled. 0N/A * @param index the index of the cell to select 0N/A * @see ListSelectionModel#setSelectionInterval 0N/A * @see #isSelectedIndex 0N/A * @see #addListSelectionListener 0N/A * description: The index of the selected cell. 0N/A * Changes the selection to be the set of indices specified by the given 0N/A * array. Indices greater than or equal to the model size are ignored. 0N/A * This is a convenience method that clears the selection and then uses 0N/A * {@code addSelectionInterval} on the selection model to add the indices. 0N/A * Refer to the documentation of the selection model class being used for 0N/A * details on how values less than {@code 0} are handled. 0N/A * @param indices an array of the indices of the cells to select, 0N/A * @see ListSelectionModel#addSelectionInterval 0N/A * @see #isSelectedIndex 0N/A * @see #addListSelectionListener 0N/A * @throws NullPointerException if the given array is {@code null} 0N/A * Returns an array of all the selected values, in increasing order based 0N/A * on their indices in the list. 0N/A * @return the selected values, or an empty array if nothing is selected 0N/A * @see #isSelectedIndex 0N/A * @see #addListSelectionListener 0N/A * Returns the smallest selected cell index; <i>the selection</i> when only 0N/A * a single item is selected in the list. When multiple items are selected, 0N/A * it is simply the smallest selected index. Returns {@code -1} if there is 0N/A * This method is a cover that delegates to {@code getMinSelectionIndex}. 0N/A * @return the smallest selected cell index 0N/A * @see #getMinSelectionIndex 0N/A * @see #addListSelectionListener 0N/A * Returns the value for the smallest selected cell index; 0N/A * <i>the selected value</i> when only a single item is selected in the 0N/A * list. When multiple items are selected, it is simply the value for the 0N/A * smallest selected index. Returns {@code null} if there is no selection. 0N/A * This is a convenience method that simply returns the model value for 0N/A * {@code getMinSelectionIndex}. 0N/A * @return the first selected value 0N/A * @see #getMinSelectionIndex 0N/A * @see #addListSelectionListener 0N/A * Selects the specified object from the list. 0N/A * @param anObject the object to select 0N/A * @param shouldScroll {@code true} if the list should scroll to display 0N/A * the selected object, if one exists; otherwise {@code false} 0N/A repaint();
/** FIX-ME setSelectedIndex does not redraw all the time with the basic l&f**/ 0N/A repaint();
/** FIX-ME setSelectedIndex does not redraw all the time with the basic l&f**/ 0N/A * --- The Scrollable Implementation --- 0N/A * Computes the size of viewport needed to display {@code visibleRowCount} 0N/A * rows. The value returned by this method depends on the layout 0N/A * <b>{@code VERTICAL}:</b> 0N/A * This is trivial if both {@code fixedCellWidth} and {@code fixedCellHeight} 0N/A * have been set (either explicitly or by specifying a prototype cell value). 0N/A * The width is simply the {@code fixedCellWidth} plus the list's horizontal 0N/A * insets. The height is the {@code fixedCellHeight} multiplied by the 0N/A * {@code visibleRowCount}, plus the list's vertical insets. 0N/A * If either {@code fixedCellWidth} or {@code fixedCellHeight} haven't been 0N/A * specified, heuristics are used. If the model is empty, the width is 0N/A * the {@code fixedCellWidth}, if greater than {@code 0}, or a hard-coded 0N/A * value of {@code 256}. The height is the {@code fixedCellHeight} multiplied 0N/A * by {@code visibleRowCount}, if {@code fixedCellHeight} is greater than 0N/A * {@code 0}, otherwise it is a hard-coded value of {@code 16} multiplied by 0N/A * {@code visibleRowCount}. 0N/A * If the model isn't empty, the width is the preferred size's width, 0N/A * typically the width of the widest list element. The height is the 0N/A * {@code fixedCellHeight} multiplied by the {@code visibleRowCount}, 0N/A * plus the list's vertical insets. 0N/A * <b>{@code VERTICAL_WRAP} or {@code HORIZONTAL_WRAP}:</b> 0N/A * This method simply returns the value from {@code getPreferredSize}. 0N/A * The list's {@code ListUI} is expected to override {@code getPreferredSize} 0N/A * to return an appropriate value. 0N/A * @return a dimension containing the size of the viewport needed 0N/A * to display {@code visibleRowCount} rows 0N/A * @see #getPreferredScrollableViewportSize 0N/A * @see #setPrototypeCellValue 0N/A // Will only happen if UI null, shouldn't matter what we return 0N/A * Returns the distance to scroll to expose the next or previous 0N/A * row (for vertical scrolling) or column (for horizontal scrolling). 0N/A * For horizontal scrolling, if the layout orientation is {@code VERTICAL}, 0N/A * then the list's font size is returned (or {@code 1} if the font is 0N/A * @param visibleRect the view area visible within the viewport 0N/A * @param orientation {@code SwingConstants.HORIZONTAL} or 0N/A * {@code SwingConstants.VERTICAL} 0N/A * @param direction less or equal to zero to scroll up/back, 0N/A * @return the "unit" increment for scrolling in the specified direction; 0N/A * @see #getScrollableBlockIncrement 0N/A * @see Scrollable#getScrollableUnitIncrement 0N/A * @throws IllegalArgumentException if {@code visibleRect} is {@code null}, or 0N/A * {@code orientation} isn't one of {@code SwingConstants.VERTICAL} or 0N/A * {@code SwingConstants.HORIZONTAL} 0N/A /* The first row is completely visible and it's row 0. 0N/A /* The first row is completely visible, return the 0N/A * height of the previous row or 0 if the first row 0N/A * is the top row of the list. 0N/A /* The first row is partially visible, return the 0N/A * height of hidden part. 0N/A // Show remainder of leading cell 0N/A // Hide rest of leading cell 0N/A // Hide rest of leading cell 0N/A // ASSUME: All cells are the same width 0N/A * Returns the distance to scroll to expose the next or previous block. 0N/A * For vertical scrolling, the following rules are used: 0N/A * <li>if scrolling down, returns the distance to scroll so that the last 0N/A * visible element becomes the first completely visible element 0N/A * <li>if scrolling up, returns the distance to scroll so that the first 0N/A * visible element becomes the last completely visible element 0N/A * <li>returns {@code visibleRect.height} if the list is empty 0N/A * For horizontal scrolling, when the layout orientation is either 0N/A * {@code VERTICAL_WRAP} or {@code HORIZONTAL_WRAP}: 0N/A * <li>if scrolling right, returns the distance to scroll so that the 0N/A * last visible element becomes 0N/A * the first completely visible element 0N/A * <li>if scrolling left, returns the distance to scroll so that the first 0N/A * visible element becomes the last completely visible element 0N/A * <li>returns {@code visibleRect.width} if the list is empty 0N/A * For horizontal scrolling and {@code VERTICAL} orientation, 0N/A * returns {@code visibleRect.width}. 0N/A * Note that the value of {@code visibleRect} must be the equal to 0N/A * {@code this.getVisibleRect()}. 0N/A * @param visibleRect the view area visible within the viewport 0N/A * @param orientation {@code SwingConstants.HORIZONTAL} or 0N/A * {@code SwingConstants.VERTICAL} 0N/A * @param direction less or equal to zero to scroll up/back, 0N/A * @return the "block" increment for scrolling in the specified direction; 0N/A * @see #getScrollableUnitIncrement 0N/A * @see Scrollable#getScrollableBlockIncrement 0N/A * @throws IllegalArgumentException if {@code visibleRect} is {@code null}, or 0N/A * {@code orientation} isn't one of {@code SwingConstants.VERTICAL} or 0N/A * {@code SwingConstants.HORIZONTAL} 0N/A // last cell is the lowest left cell 0N/A /* Scroll Right (in ltr mode) or Scroll Left (in rtl mode) */ 0N/A // position is upper right if ltr, or upper left otherwise 0N/A /* Scroll Left (in ltr mode) or Scroll Right (in rtl mode) */ 0N/A // position is upper left corner of the visibleRect shifted 0N/A // left by the visibleRect.width if ltr, or upper right shifted 0N/A // right by the visibleRect.width otherwise 0N/A // the right of the first cell 0N/A * Returns {@code true} if this {@code JList} is displayed in a 0N/A * {@code JViewport} and the viewport is wider than the list's 0N/A * preferred width, or if the layout orientation is {@code HORIZONTAL_WRAP} 0N/A * and {@code visibleRowCount <= 0}; otherwise returns {@code false}. 0N/A * If {@code false}, then don't track the viewport's width. This allows 0N/A * horizontal scrolling if the {@code JViewport} is itself embedded in a 0N/A * {@code JScrollPane}. 0N/A * @return whether or not an enclosing viewport should force the list's 0N/A * width to match its own 0N/A * @see Scrollable#getScrollableTracksViewportWidth 0N/A * Returns {@code true} if this {@code JList} is displayed in a 0N/A * {@code JViewport} and the viewport is taller than the list's 0N/A * preferred height, or if the layout orientation is {@code VERTICAL_WRAP} 0N/A * and {@code visibleRowCount <= 0}; otherwise returns {@code false}. 0N/A * If {@code false}, then don't track the viewport's height. This allows 0N/A * vertical scrolling if the {@code JViewport} is itself embedded in a 0N/A * {@code JScrollPane}. 0N/A * @return whether or not an enclosing viewport should force the list's 0N/A * height to match its own 0N/A * @see Scrollable#getScrollableTracksViewportHeight 0N/A * See {@code readObject} and {@code writeObject} in {@code JComponent} 0N/A * for more information about serialization in Swing. 0N/A * Returns a {@code String} representation of this {@code JList}. 0N/A * This method is intended to be used only for debugging purposes, 0N/A * and the content and format of the returned {@code String} may vary 0N/A * between implementations. The returned {@code String} may be empty, 0N/A * but may not be {@code null}. 0N/A * @return a {@code String} representation of this {@code JList}. 0N/A * --- Accessibility Support --- 0N/A * Gets the {@code AccessibleContext} associated with this {@code JList}. 0N/A * For {@code JList}, the {@code AccessibleContext} takes the form of an 0N/A * {@code AccessibleJList}. 0N/A * A new {@code AccessibleJList} instance is created if necessary. 0N/A * @return an {@code AccessibleJList} that serves as the 0N/A * {@code AccessibleContext} of this {@code JList} 0N/A * This class implements accessibility support for the 0N/A * {@code JList} class. It provides an implementation of the 0N/A * Java Accessibility API appropriate to list user-interface 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * Property Change Listener change method. Used to track changes 0N/A * to the DataModel and ListSelectionModel, in order to re-set 0N/A * listeners to those for reporting changes there via the Accessibility 0N/A * PropertyChange mechanism. 0N/A * @param e PropertyChangeEvent 0N/A // re-set listData listeners 0N/A // re-set listSelectionModel listeners 0N/A * List Selection Listener value change method. Used to fire 0N/A * the property change 0N/A * @param e ListSelectionEvent 0N/A // Process the State changes for Multiselectable 0N/A * List Data Listener interval added method. Used to fire the visible data property change 0N/A * @param e ListDataEvent 0N/A * List Data Listener interval removed method. Used to fire the visible data property change 0N/A * @param e ListDataEvent 0N/A * List Data Listener contents changed method. Used to fire the visible data property change 0N/A * @param e ListDataEvent 0N/A // AccessibleContext methods 0N/A * Get the state set of this object. 0N/A * @return an instance of AccessibleState containing the current state 0N/A * @see AccessibleState 0N/A * Get the role of this object. 0N/A * @return an instance of AccessibleRole describing the role of the 0N/A * @see AccessibleRole 0N/A * Returns the <code>Accessible</code> child contained at 0N/A * the local coordinate <code>Point</code>, if one exists. 0N/A * Otherwise returns <code>null</code>. 0N/A * @return the <code>Accessible</code> at the specified 0N/A * location, if it exists 0N/A * Returns the number of accessible children in the object. If all 0N/A * of the children of this object implement Accessible, than this 0N/A * method should return the number of children of this object. 0N/A * @return the number of accessible children in the object. 0N/A * Return the nth Accessible child of the object. 0N/A * @param i zero-based index of child 0N/A * @return the nth Accessible child of the object 0N/A * Get the AccessibleSelection associated with this object. In the 0N/A * implementation of the Java Accessibility API for this class, 0N/A * return this object, which is responsible for implementing the 0N/A * AccessibleSelection interface on behalf of itself. 0N/A * @return this object 0N/A // AccessibleSelection methods 0N/A * Returns the number of items currently selected. 0N/A * If no items are selected, the return value will be 0. 0N/A * @return the number of items currently selected. 0N/A * Returns an Accessible representing the specified selected item 0N/A * in the object. If there isn't a selection, or there are 0N/A * fewer items selected than the integer passed in, the return 0N/A * value will be <code>null</code>. 0N/A * @param i the zero-based index of selected items 0N/A * @return an Accessible containing the selected item 0N/A * Returns true if the current child of this object is selected. 0N/A * @param i the zero-based index of the child in this Accessible 0N/A * @see AccessibleContext#getAccessibleChild 0N/A * Adds the specified selected item in the object to the object's 0N/A * selection. If the object supports multiple selections, 0N/A * the specified item is added to any existing selection, otherwise 0N/A * it replaces any existing selection in the object. If the 0N/A * specified item is already selected, this method has no effect. 0N/A * @param i the zero-based index of selectable items 0N/A * Removes the specified selected item in the object from the object's 0N/A * selection. If the specified item isn't currently selected, this 0N/A * method has no effect. 0N/A * @param i the zero-based index of selectable items 0N/A * Clears the selection in the object, so that nothing in the 0N/A * object is selected. 0N/A * Causes every selected item in the object to be selected 0N/A * if the object supports multiple selections. 0N/A * This class implements accessibility support appropriate 0N/A * for list children. 0N/A // Accessible Methods 0N/A * Get the AccessibleContext for this object. In the 0N/A * implementation of the Java Accessibility API for this class, 0N/A * returns this object, which is its own AccessibleContext. 0N/A * @return this object 0N/A // AccessibleContext methods 0N/A * Get the AccessibleComponent associated with this object. In the 0N/A * implementation of the Java Accessibility API for this class, 0N/A * return this object, which is responsible for implementing the 0N/A * AccessibleComponent interface on behalf of itself. 0N/A * @return this object 0N/A return this;
// to override getBounds() 0N/A // AccessibleComponent methods 0N/A // The UI incorrectly returns a -1 for the last 0N/A // visible index if the list is smaller than the 0N/A * Returns the icon for the element renderer, as the only item 0N/A * of an array of <code>AccessibleIcon</code>s or a <code>null</code> array 0N/A * if the renderer component contains no icons. 0N/A * @return an array containing the accessible icon 0N/A * or a <code>null</code> array if none 0N/A }
// inner class AccessibleJListChild 0N/A }
// inner class AccessibleJList