E - 此列表的元素的类型
public class JList<E> extends JComponent implements Scrollable, Accessible
ListModel维护列表的内容。
可以很容易地显示对象的数组或向量,使用JList构造函数自动构建只读ListModel实例为您提供:
// Create a JList that displays strings from an array String[] data = {"one", "two", "three", "four"}; JList<String> myList = new JList<String>(data); // Create a JList that displays the superclasses of JList.class, by // creating it with a Vector populated with this data Vector<Class<?>> superClasses = new Vector<Class<?>>(); Class<JList> rootClass = javax.swing.JList.class; for(Class<?> cls = rootClass; cls != null; cls = cls.getSuperclass()) { superClasses.addElement(cls); } JList<Class<?>> myList = new JList<Class<?>>(superClasses); // The automatically created model is stored in JList's "model" // property, which you can retrieve ListModel<Class<?>> model = myList.getModel(); for(int i = 0; i < model.getSize(); i++) { System.out.println(model.getElementAt(i)); }
甲ListModel可以直接提供给JList由一个构造的方式或setModel方法。 内容不需要是静态的 - 项目的数量和项目的值可以随着时间的推移而改变。 正确的ListModel实现通知已经添加到它的javax.swing.event.ListDataListener s的集合,每次发生更改。 这些更改的特征在于javax.swing.event.ListDataEvent ,它标识已修改,添加或删除的列表索引的范围。 JList的ListUI负责与变化保持视觉呈现最新,通过监听模式。
简单,动态内容, JList程序可以使用DefaultListModel类来维护列表元素。 该类实现了ListModel接口,并提供了一个类似java.util.Vector的API。 需要更自定义ListModel程序可能希望子类化AbstractListModel ,它为管理和通知监听器提供了基本的支持。 例如,只读实现AbstractListModel :
// This list model has about 2^16 elements. Enjoy scrolling. ListModel<String> bigData = new AbstractListModel<String>() { public int getSize() { return Short.MAX_VALUE; } public String getElementAt(int index) { return "Index " + index; } };
一个的选择状态JList被另一个单独的模型,的一个实例管理ListSelectionModel 。 JList在构建中使用选择模型初始化,并且还包含查询或设置此选择模型的方法。 另外, JList提供了便于管理选择的方便的方法。 这些方法,例如setSelectedIndex和getSelectedValue ,是涵盖与选择模型交互的细节的覆盖方法。 默认情况下, JList的选择模型被配置为允许每次选择项目的任意组合; 选择模式MULTIPLE_INTERVAL_SELECTION 。 选择模式可以直接在选型上更改,也可以通过JList的封面方式进行更改。 响应用户手势更新选择模型的责任在于列表的ListUI 。
正确的ListSelectionModel实现通知每次发生更改选择时已添加到其中的javax.swing.event.ListSelectionListener s的集合。 这些更改的特征是javax.swing.event.ListSelectionEvent ,它标识选择更改的范围。
收听列表选择更改的首选方法是直接添加ListSelectionListener s到JList 。 JList然后照顾听选择模型并通知你的听众的变化。
为了保持列表的视觉表示更新,聆听选择更改的责任在于列表的ListUI 。
JList中的单元格绘制由名为单元格渲染器的委托处理,作为cellRenderer属性安装在列表中。 渲染器提供了一个java.awt.Component ,它像“橡皮图章”一样用于绘制单元格。 每次单元格需要绘制时,列表的ListUI会向单元格渲染器询问组件,将其移动到位,并通过其paint方法绘制单元格的内容。 使用JLabel组件渲染的默认单元格渲染器由列表的ListUI 。 您可以使用以下代码替换您自己的渲染器:
// Display an icon and a string for each object in the list. class MyCellRenderer extends JLabel implements ListCellRenderer<Object> { final static ImageIcon longIcon = new ImageIcon("long.gif"); final static ImageIcon shortIcon = new ImageIcon("short.gif"); // This is the only method defined by ListCellRenderer. // We just reconfigure the JLabel each time we're called. public Component getListCellRendererComponent( JList<?> list, // the list Object value, // value to display int index, // cell index boolean isSelected, // is the cell selected boolean cellHasFocus) // does the cell have focus { String s = value.toString(); setText(s); setIcon((s.length() > 10) ? longIcon : shortIcon); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); setOpaque(true); return this; } } myList.setCellRenderer(new MyCellRenderer());
单元格渲染器的另一个工作是帮助确定列表的大小信息。 默认情况下,列表的ListUI通过询问单元格渲染器的每个列表项的首选大小来确定单元格的大小。 这对于大型物品清单来说可能是昂贵的。 为了避免这些计算,您可以在列表中设置fixedCellWidth和fixedCellHeight ,或者根据单个原型值自动计算这些值:
JList<String> bigDataList = new JList<String>(bigData); // We don't want the JList implementation to compute the width // or height of all of the list cells, so we give it a string // that's as big as we'll need for any cell. It uses this to // compute values for the fixedCellWidth and fixedCellHeight // properties. bigDataList.setPrototypeCellValue("Index 1234567890");
JList不直接实现滚动。 要创建一个滚动的列表,使其成为JScrollPane的视口视图。 例如:
JScrollPane scrollPane = new JScrollPane(myList);
// Or in two steps:
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().setView(myList);
JList不提供双击或三键(或N)鼠标点击的任何特殊处理,但如果您想对这些事件采取行动,可以轻松添加MouseListener 。 使用locationToIndex方法来确定单击哪个单元格。 例如:
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = list.locationToIndex(e.getPoint());
System.out.println("Double clicked on Item " + index);
}
}
};
list.addMouseListener(mouseListener);
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
| Modifier and Type | Class and Description |
|---|---|
protected class |
JList.AccessibleJList
这个类实现了可访问性支持
JList类。
|
static class |
JList.DropLocation
的一个子类
TransferHandler.DropLocation表示用于一个放置位置
JList 。
|
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static int |
HORIZONTAL_WRAP
表示“报纸风格”布局,单元格水平方向垂直。
|
static int |
VERTICAL
表示单个列中的单元格的垂直布局;
默认布局。
|
static int |
VERTICAL_WRAP
表示“报纸风格”布局,单元格横向垂直流动。
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JList()
构造一个空的只读模型的
JList 。
|
JList(E[] listData)
构造一个
JList ,显示指定数组中的元素。
|
JList(ListModel<E> dataModel)
构造一个
JList ,其显示从指定的,元件
non-null ,模型。
|
JList(Vector<? extends E> listData)
构造一个
JList ,显示在指定的元素
Vector 。
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListSelectionListener(ListSelectionListener listener)
将一个监听器添加到列表中,每次发生更改时都会被通知;
倾听选择状态变化的首选方式。
|
void |
addSelectionInterval(int anchor, int lead)
将选择设置为指定间隔与当前选择的并集。
|
void |
clearSelection()
清除选择;
调用此方法后, isSelectionEmpty将返回true 。
|
protected ListSelectionModel |
createSelectionModel()
返回一个 DefaultListSelectionModel的实例;
在建设期间呼吁初始化列表的选择模型属性。
|
void |
ensureIndexIsVisible(int index)
在封闭的视口中滚动列表,使指定的单元格完全可见。
|
protected void |
fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
通知
ListSelectionListener s直接添加到选择模型所做的选择更改列表中。
|
AccessibleContext |
getAccessibleContext()
获取
AccessibleContext与此相关
JList 。
|
int |
getAnchorSelectionIndex()
返回锚选择索引。
|
Rectangle |
getCellBounds(int index0, int index1)
返回列表坐标系中由两个索引指定的单元格范围的边界矩形。
|
ListCellRenderer<? super E> |
getCellRenderer()
返回负责绘画列表项的对象。
|
boolean |
getDragEnabled()
返回是否启用自动拖动处理。
|
JList.DropLocation |
getDropLocation()
返回该组件应在视觉上作为放置位置的DnD操作期间组件上方指示,或位置
null如果没有位置是当前被显示。
|
DropMode |
getDropMode()
返回此组件的放置模式。
|
int |
getFirstVisibleIndex()
返回当前可见的最小列表索引。
|
int |
getFixedCellHeight()
返回
fixedCellHeight属性的值。
|
int |
getFixedCellWidth()
返回
fixedCellWidth属性的值。
|
int |
getLastVisibleIndex()
返回当前可见的最大列表索引。
|
int |
getLayoutOrientation()
返回列表的布局方向属性:
VERTICAL如果布局是单列单元格,
VERTICAL_WRAP如果布局是“报纸样式”,内容垂直然后水平流动,或
HORIZONTAL_WRAP如果布局是“报纸样式”与内容水平流动然后垂直。
|
int |
getLeadSelectionIndex()
返回引导选择索引。
|
ListSelectionListener[] |
getListSelectionListeners()
返回所有的数组
ListSelectionListener加入到这个S
JList途经
addListSelectionListener 。
|
int |
getMaxSelectionIndex()
返回最大的所选单元
-1引,如果选择为空,则返回-1。
|
int |
getMinSelectionIndex()
返回最小选择的单元
-1引,如果选择为空,则返回-1。
|
ListModel<E> |
getModel()
返回保存由
JList组件显示的项目列表的数据模型。
|
int |
getNextMatch(String prefix, int startIndex, Position.Bias bias)
返回下一个列表元素,其中
toString值以给定的前缀开始。
|
Dimension |
getPreferredScrollableViewportSize()
计算显示
visibleRowCount行所需的视口大小。
|
E |
getPrototypeCellValue()
返回“原型”单元格值 - 用于计算单元格的固定宽度和高度的值。
|
int |
getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
返回要滚动以显示下一个或上一个块的距离。
|
boolean |
getScrollableTracksViewportHeight()
返回 true如果JList显示在JViewport和视口比列表的首选高度更高,或者布局方向为VERTICAL_WRAP和visibleRowCount <= 0 ;
否则返回false 。
|
boolean |
getScrollableTracksViewportWidth()
返回 true如果此JList被显示在JViewport和视口比所述列表的优选宽度,或者如果布局方向为HORIZONTAL_WRAP和visibleRowCount <= 0 ;
否则返回false 。
|
int |
getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
返回滚动的距离以显示下一行或上一行(垂直滚动)或列(用于水平滚动)。
|
int |
getSelectedIndex()
返回最小的选定单元格索引;
在列表中仅选择单个项目时的选择。
|
int[] |
getSelectedIndices()
以递增的顺序返回所有选定索引的数组。
|
E |
getSelectedValue()
返回最小选定单元索引的值;
在列表中仅选择单个项目时的选定值 。
|
Object[] |
getSelectedValues()
已弃用
截至JDK 1.7,由
getSelectedValuesList()替代
|
List<E> |
getSelectedValuesList()
根据列表中的索引,按照增加的顺序返回所有选定项目的列表。
|
Color |
getSelectionBackground()
返回用于绘制所选项目背景的颜色。
|
Color |
getSelectionForeground()
返回用于绘制所选项目前景的颜色。
|
int |
getSelectionMode()
返回列表的当前选择模式。
|
ListSelectionModel |
getSelectionModel()
返回当前的选择模型。
|
String |
getToolTipText(MouseEvent event)
返回用于给定事件的工具提示文本。
|
ListUI |
getUI()
返回
ListUI ,呈现此组件的外观和感觉对象。
|
String |
getUIClassID()
返回
"ListUI" ,该
UIDefaults用于查找该名关键
javax.swing.plaf.ListUI类定义的外观和感觉这个组件。
|
boolean |
getValueIsAdjusting()
返回选择模型的
isAdjusting属性的值。
|
int |
getVisibleRowCount()
返回
visibleRowCount属性的值。
|
Point |
indexToLocation(int index)
返回列表坐标系中指定项目的原点。
|
boolean |
isSelectedIndex(int index)
如果选择了指定的索引,则返回
true ,否则为
false 。
|
boolean |
isSelectionEmpty()
如果没有选择,返回
true ,否则
false 。
|
int |
locationToIndex(Point location)
返回最接近列表坐标系中给定位置的单元格索引。
|
protected String |
paramString()
返回
String如此表示
JList 。
|
void |
removeListSelectionListener(ListSelectionListener listener)
从列表中删除选择侦听器。
|
void |
removeSelectionInterval(int index0, int index1)
将选择设置为指定间隔和当前选择的设置差。
|
void |
setCellRenderer(ListCellRenderer<? super E> cellRenderer)
设置用于绘制列表中每个单元格的委托。
|
void |
setDragEnabled(boolean b)
打开或关闭自动拖动处理。
|
void |
setDropMode(DropMode dropMode)
设置此组件的下拉模式。
|
void |
setFixedCellHeight(int height)
设置要用于列表中每个单元格的高度的固定值。
|
void |
setFixedCellWidth(int width)
设置要用于列表中每个单元格宽度的固定值。
|
void |
setLayoutOrientation(int layoutOrientation)
定义列表单元格的布局方式。
|
void |
setListData(E[] listData)
构造一个只读
ListModel从项目的数组,并调用
setModel这种模式。
|
void |
setListData(Vector<? extends E> listData)
构造一个只读
ListModel从
Vector并调用
setModel这种模式。
|
void |
setModel(ListModel<E> model)
设置表示列表的内容或“值”的模型,通知属性更改侦听器,然后清除列表的选择。
|
void |
setPrototypeCellValue(E prototypeCellValue)
设置
prototypeCellValue属性,然后(如果新值为
non-null ),通过从单元格渲染器请求单元格渲染器组件给定值(和索引0),并使用该组件的首选大小来计算
fixedCellWidth和
fixedCellHeight属性。
|
void |
setSelectedIndex(int index)
选择单个单元格。
|
void |
setSelectedIndices(int[] indices)
将选择更改为给定数组指定的索引集。
|
void |
setSelectedValue(Object anObject, boolean shouldScroll)
从列表中选择指定的对象。
|
void |
setSelectionBackground(Color selectionBackground)
设置用于绘制所选项目背景的颜色,哪些单元格渲染器可以使用填充所选单元格。
|
void |
setSelectionForeground(Color selectionForeground)
设置用于绘制所选项目的前景的颜色,哪些单元格渲染器可用于渲染文本和图形。
|
void |
setSelectionInterval(int anchor, int lead)
选择指定的间隔。
|
void |
setSelectionMode(int selectionMode)
设置列表的选择模式。
|
void |
setSelectionModel(ListSelectionModel selectionModel)
将该列表的
selectionModel设置为非
null
ListSelectionModel实现。
|
void |
setUI(ListUI ui)
设置
ListUI ,呈现此组件的外观和感觉对象。
|
void |
setValueIsAdjusting(boolean b)
设置选择模型的
valueIsAdjusting属性。
|
void |
setVisibleRowCount(int visibleRowCount)
设置 visibleRowCount属性,具有不同的含义,具体取决于布局方向:对于VERTICAL布局方向,这将设置要显示的首选行数,而不需要滚动;
对于其他取向,它影响细胞的包裹。
|
void |
updateUI()
将
ListUI属性重新设置为当前外观所提供的值。
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic static final int VERTICAL
setLayoutOrientation(int) ,
Constant Field Values
public static final int VERTICAL_WRAP
setLayoutOrientation(int) ,
Constant Field Values
public static final int HORIZONTAL_WRAP
setLayoutOrientation(int) ,
Constant Field Values
public JList(ListModel<E> dataModel)
JList ,其显示从指定的,元件non-null ,模型。
所有JList函数都委托给这个。
此构造与注册名单ToolTipManager ,允许本小区渲染器提供工具提示。
dataModel - 列表的模型
IllegalArgumentException - 如果型号是
null
public JList(E[] listData)
JList ,显示指定数组中的元素。
此构造函数为给定的数组创建一个只读模型,然后委托给构造函数,该构造函数采用ListModel 。
尝试将null值传递给此方法会导致未定义的行为,并且很有可能出现异常。 创建的模型直接引用给定的数组。 构造列表后尝试修改数组会导致未定义的行为。
listData - 要加载到数据模型的对象数组,
non-null
public JList(Vector<? extends E> listData)
JList ,显示在指定的元素Vector 。
此构造会为给定只读模式Vector ,然后委托给带有构造ListModel 。
尝试将null值传递给此方法会导致未定义的行为,并且最有可能发生异常。 创建的模型直接引用给定的Vector 。 在构建列表后尝试修改Vector会导致未定义的行为。
listData -的
Vector被加载到数据模型,
non-null
public JList()
JList 。
public ListUI getUI()
ListUI ,呈现此组件的外观和感觉对象。
ListUI对象
public void setUI(ListUI ui)
ListUI ,呈现此组件的外观和感觉对象。
ui -
ListUI对象
UIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
ListUI属性重新设置为当前外观所提供的值。
如果当前的单元格渲染器是由开发人员安装的(而不是外观和感觉本身),这也会导致单元格渲染器及其子代码更新,方法是调用SwingUtilities.updateComponentTreeUI 。
public String getUIClassID()
"ListUI" ,该
UIDefaults用于查找该名关键
javax.swing.plaf.ListUI类定义的外观和感觉这个组件。
getUIClassID在
JComponent
JComponent.getUIClassID() ,
UIDefaults.getUI(javax.swing.JComponent)
public E getPrototypeCellValue()
null如果没有这样的值。
prototypeCellValue属性
setPrototypeCellValue(E)
public void setPrototypeCellValue(E prototypeCellValue)
prototypeCellValue属性,然后(如果新值为non-null ),通过从单元格渲染器请求单元格渲染器组件给定值(和索引0),并使用该组件的首选大小来计算fixedCellWidth和fixedCellHeight属性。
当列表太长以至于不允许ListUI计算每个单元格的宽度/高度时,此方法很有用,并且有一个已知占据与其他单元格相同的空间的单个单元格值,即所谓的原型。
虽然所有三种的prototypeCellValue , fixedCellHeight和fixedCellWidth性质可通过该方法被修改, PropertyChangeEvent通知仅发送的时prototypeCellValue属性的变化。
要查看设置此属性的示例,请参阅上面的class description 。
此属性的默认值为null 。
这是一个JavaBeans绑定属性。
prototypeCellValue - 基于
fixedCellWidth和
fixedCellHeight
getPrototypeCellValue() ,
setFixedCellWidth(int) ,
setFixedCellHeight(int) ,
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
public int getFixedCellWidth()
fixedCellWidth属性的值。
setFixedCellWidth(int)
public void setFixedCellWidth(int width)
width是-1,单元宽度计算在ListUI通过施加getPreferredSize至细胞渲染器组件为每个列表元素。
此属性的默认值为-1 。
这是一个JavaBeans绑定属性。
width - 要用于列表中所有单元格的宽度
setPrototypeCellValue(E) ,
setFixedCellWidth(int) ,
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
public int getFixedCellHeight()
fixedCellHeight属性的值。
setFixedCellHeight(int)
public void setFixedCellHeight(int height)
height是-1,细胞高度被计算在ListUI通过施加getPreferredSize至细胞渲染器组件为每个列表元素。
此属性的默认值为-1 。
这是一个JavaBeans绑定属性。
height - 用于列表中所有单元格的高度
setPrototypeCellValue(E) ,
setFixedCellWidth(int) ,
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
public ListCellRenderer<? super E> getCellRenderer()
cellRenderer属性
setCellRenderer(javax.swing.ListCellRenderer<? super E>)
public void setCellRenderer(ListCellRenderer<? super E> cellRenderer)
如果prototypeCellValue属性为non-null ,则设置单元格渲染器也会导致重新fixedCellWidth和fixedCellHeight属性。 只有一个PropertyChangeEvent生成 - 对于cellRenderer属性。
该属性的默认值由ListUI代理提供,即通过外观实现。
这是一个JavaBeans绑定属性。
cellRenderer - 绘制列表单元格的
ListCellRenderer
getCellRenderer()
public Color getSelectionForeground()
DefaultListCellRenderer使用此颜色来绘制所选状态的项目的前景,大多数ListUI实现中安装的渲染器也是如此。
setSelectionForeground(java.awt.Color) , DefaultListCellRenderer
public void setSelectionForeground(Color selectionForeground)
DefaultListCellRenderer使用此颜色绘制所选状态的项目的前景,大多数ListUI实现中安装的渲染器也是如此。
该属性的默认值由外观实现定义。
这是一个JavaBeans绑定属性。
selectionForeground -
Color在前台使用选定的列表项
getSelectionForeground() , setSelectionBackground(java.awt.Color) , JComponent.setForeground(java.awt.Color) , JComponent.setBackground(java.awt.Color) , JComponent.setFont(java.awt.Font) , DefaultListCellRenderer
public Color getSelectionBackground()
DefaultListCellRenderer使用此颜色绘制所选状态的项目的背景,大多数ListUI实现中安装的渲染器也是如此。
setSelectionBackground(java.awt.Color) , DefaultListCellRenderer
public void setSelectionBackground(Color selectionBackground)
DefaultListCellRenderer使用这种颜色来填充所选状态的项目的背景,大多数ListUI实现中安装的渲染器也是如此。
该属性的默认值由外观实现定义。
这是一个JavaBeans绑定属性。
selectionBackground -
Color用于所选单元格的背景
getSelectionBackground() , setSelectionForeground(java.awt.Color) , JComponent.setForeground(java.awt.Color) , JComponent.setBackground(java.awt.Color) , JComponent.setFont(java.awt.Font) , DefaultListCellRenderer
public int getVisibleRowCount()
visibleRowCount属性的值。
有关如何解释此值的详细信息,请参阅setVisibleRowCount(int)的文档 。
visibleRowCount属性。
setVisibleRowCount(int)
public void setVisibleRowCount(int visibleRowCount)
visibleRowCount属性,具有不同的含义:对于VERTICAL布局方向,这将设置要显示的首选行数,而不需要滚动;
对于其他取向,它影响细胞的包裹。
在VERTICAL方向:
设置此属性会影响getPreferredScrollableViewportSize()方法的返回值,该方法用于计算封闭视口的首选大小。 有关更多详细信息,请参阅该方法的文档。
在HORIZONTAL_WRAP和VERTICAL_WRAP方向:
这会影响细胞的包装。 有关详细信息,请参阅setLayoutOrientation(int)的文档 。
此属性的默认值为8 。
使用负值调用此方法会导致属性设置为0 。
这是一个JavaBeans绑定属性。
visibleRowCount - 一个整数,指定要显示的首选行数,而不需要滚动
getVisibleRowCount() , getPreferredScrollableViewportSize() , setLayoutOrientation(int) , JComponent.getVisibleRect() , JViewport
public int getLayoutOrientation()
VERTICAL如果布局是单列单元格,
VERTICAL_WRAP如果布局是“报纸样式”,内容垂直然后水平流动,或
HORIZONTAL_WRAP如果布局是“报纸样式”与内容水平流动然后垂直。
layoutOrientation属性
setLayoutOrientation(int)
public void setLayoutOrientation(int layoutOrientation)
JList 。
细胞可以通过以下方式之一进行布置:
VERTICAL: 0
1
2
3
4
HORIZONTAL_WRAP: 0 1 2
3 4
VERTICAL_WRAP: 0 3
1 4
2
这些布局的描述如下:
Value
描述
VERTICAL Cells are layed out vertically in a single column. HORIZONTAL_WRAP Cells are layed out horizontally, wrapping to a new row as necessary. If the visibleRowCount property is less than or equal to zero, wrapping is determined by the width of the list; otherwise wrapping is done in such a way as to ensure visibleRowCount rows in the list. VERTICAL_WRAP Cells are layed out vertically, wrapping to a new column as necessary. If the visibleRowCount property is less than or equal to zero, wrapping is determined by the height of the list; otherwise wrapping is done at visibleRowCount rows.
此属性的默认值为VERTICAL 。
layoutOrientation -新的布局方向,其一:
VERTICAL ,
HORIZONTAL_WRAP或
VERTICAL_WRAP
IllegalArgumentException - 如果
layoutOrientation不是允许的值之一
getLayoutOrientation() ,
setVisibleRowCount(int) ,
getScrollableTracksViewportHeight() ,
getScrollableTracksViewportWidth()
public int getFirstVisibleIndex()
componentOrientation ,第一个可见单元格被发现最接近列表的左上角。
从右到左的方向,它被发现最靠近右上角。
如果没有可见或列表为空,则返回-1 。
请注意,返回的单元格只能部分可见。
getLastVisibleIndex() ,
JComponent.getVisibleRect()
public int getLastVisibleIndex()
-1 。
请注意,返回的单元格只能部分可见。
getFirstVisibleIndex() ,
JComponent.getVisibleRect()
public void ensureIndexIsVisible(int index)
scrollRectToVisible与指定单元格的边界。
为方便上班, JList必须在JViewport 。
如果给定的索引在列表的单元格范围之外,则此方法不会产生任何结果。
index - 单元格的索引使其可见
JComponent.scrollRectToVisible(java.awt.Rectangle) ,
JComponent.getVisibleRect()
public void setDragEnabled(boolean b)
true ,并且列表的TransferHandler需要为non-null 。
dragEnabled属性的默认值为false 。
尊重这个财产的工作,并认识到一个用户拖动手势,在于外观和感觉的实现,特别是列表的ListUI 。 当启用自动拖动处理,最外观和感觉(包括那些继承BasicLookAndFeel ),开始一拖每当用户按下在项上的鼠标按钮,然后将鼠标移动几个像素拖放操作。 因此,将此属性设置为true可以对选择行为有一个微妙的影响。
如果一个外观使用的是忽略这个属性,你仍然可以开始拖拽,并通过调用拖放操作exportAsDrag上的列表中的TransferHandler 。
b - 是否启用自动拖动处理
HeadlessException - 如果
b是
true和
GraphicsEnvironment.isHeadless()返回
true
GraphicsEnvironment.isHeadless() , getDragEnabled() , JComponent.setTransferHandler(javax.swing.TransferHandler) , TransferHandler
public boolean getDragEnabled()
dragEnabled属性
setDragEnabled(boolean)
public final void setDropMode(DropMode dropMode)
DropMode.USE_SELECTION 。
但是,为了改善用户体验,建议使用其他模式之一。
例如, DropMode.ON提供了显示所选项目的类似行为,但这样做并不影响列表中的实际选择。
JList支持以下放置模式:
DropMode.USE_SELECTION DropMode.ON DropMode.INSERT DropMode.ON_OR_INSERT TransferHandler接受丢弃,则丢弃模式才有意义。
dropMode - 使用的下拉模式
IllegalArgumentException - 如果不支持拖放模式或
null
getDropMode() , getDropLocation() , JComponent.setTransferHandler(javax.swing.TransferHandler) , TransferHandler
public final DropMode getDropMode()
setDropMode(javax.swing.DropMode)
public final JList.DropLocation getDropLocation()
null如果没有位置是当前被显示。
此方法不适用于从TransferHandler查询放置位置,因为放置位置仅在TransferHandler的canImport已返回并已允许显示位置之后设置。
当此属性更改时,组件将触发名为“dropLocation”的属性更改事件。
默认情况下,监视对此属性的更改的责任和视觉上指示放置位置的ListUI在于列表的ListUI ,它可以直接绘制和/或安装单元格渲染器。 希望实现自定义放置位置绘画和/或替换默认单元格渲染器的开发人员可能需要遵守此属性。
setDropMode(javax.swing.DropMode) ,
TransferHandler.canImport(TransferHandler.TransferSupport)
public int getNextMatch(String prefix, int startIndex, Position.Bias bias)
toString值以给定的前缀开头。
prefix - 要测试匹配的字符串
startIndex - 开始搜索的索引
bias - 搜索方向,PositionBias.Forward或Position.Bias.Backward。
-1
IllegalArgumentException - 如果前缀为
null或startIndex超出范围
public String getToolTipText(MouseEvent event)
JComponent的getToolTipText以首先检查事件发生的单元格的单元格渲染器组件,返回其工具提示文本(如果有)。
此实现允许您通过在单元格渲染器组件上使用setToolTipText来指定单元格级别的工具提示文本。
注意:对于JList ,以这种方式正确显示其渲染器的工具提示, JList必须是具有ToolTipManager的注册ToolTipManager 。 此注册在构造函数中自动完成。 但是,如果稍后点JList未注册,通过调用setToolTipText(null) ,来自渲染器的提示将不再显示。
getToolTipText在
JComponent
event - 获取工具提示文本的
MouseEvent
JComponent.setToolTipText(java.lang.String) ,
JComponent.getToolTipText()
public int locationToIndex(Point location)
getCellBounds提供的方式getCellBounds点与单元格的边界进行getCellBounds 。
如果模型为空,此方法返回-1
这是一种封面方法,委托给列表ListUI 。 它返回-1如果列表中没有ListUI 。
location - 点的坐标
-1 ,或
-1
public Point indexToLocation(int index)
null 。
这是一种覆盖方法,委托给列表中的相同名称的方法ListUI 。 它返回null如果列表中没有ListUI 。
index - 细胞指数
null
public Rectangle getCellBounds(int index0, int index1)
如果较小的索引在列表的单元格范围之外,则此方法返回null 。 如果较小的索引有效,但较大的索引在列表的范围之外,则仅返回第一个索引的边界。 否则返回有效范围的范围。
这是一种覆盖方法,委托给列表中的ListUI的方法ListUI 。 它返回null如果列表中没有ListUI 。
index0 - 范围内的第一个索引
index1 - 范围内的第二个指数
null
public ListModel<E> getModel()
JList组件显示的项目列表的数据模型。
ListModel ,提供显示的项列表
setModel(javax.swing.ListModel<E>)
public void setModel(ListModel<E> model)
这是一个JavaBeans绑定属性。
model - 提供要显示的项目列表的
ListModel
IllegalArgumentException - 如果
model是
null
getModel() ,
clearSelection()
public void setListData(E[] listData)
ListModel从项目的数组,并调用setModel这种模式。
尝试将null值传递给此方法会导致未定义的行为,并且很有可能发生异常。 创建的模型直接引用给定的数组。 调用此方法后尝试修改数组会导致未定义的行为。
listData - 包含要在列表中显示的项目的数组
E
setModel(javax.swing.ListModel<E>)
public void setListData(Vector<? extends E> listData)
ListModel从Vector并调用setModel这种模式。
尝试将null值传递给此方法会导致未定义的行为,并且最有可能发生异常。 创建的模型直接引用给定的Vector 。 调用此方法后尝试修改Vector会导致未定义的行为。
listData - 一个
Vector要在列表中显示的项目的
Vector
setModel(javax.swing.ListModel<E>)
protected ListSelectionModel createSelectionModel()
DefaultListSelectionModel的实例;
在建设期间呼吁初始化列表的选择模型属性。
DefaultListSelecitonModel ,用于在施工期间初始化列表的选择模型属性
setSelectionModel(javax.swing.ListSelectionModel) , DefaultListSelectionModel
public ListSelectionModel getSelectionModel()
ListSelectionModel维护列表的选择
setSelectionModel(javax.swing.ListSelectionModel) , ListSelectionModel
protected void fireSelectionValueChanged(int firstIndex,
int lastIndex,
boolean isAdjusting)
ListSelectionListener s直接添加到对选择模型所做的选择更改的列表中。
JList侦听在选择模型中对选择所做的更改,并通过调用此方法将通知转发给添加到列表中的监听器。
此方法构造了一个ListSelectionEvent ,该列表作为源和指定的参数,并将其发送到已注册的ListSelectionListeners 。
firstIndex - 范围内的第一个指数,
<= lastIndex
lastIndex - 范围内的最后一个指数,
>= firstIndex
isAdjusting - 这是否是一系列多个事件,其中仍在进行更改
addListSelectionListener(javax.swing.event.ListSelectionListener) , removeListSelectionListener(javax.swing.event.ListSelectionListener) , ListSelectionEvent , EventListenerList
public void addListSelectionListener(ListSelectionListener listener)
JList负责监听选择模型中的选择状态更改,并向给定的侦听器通知每个更改。
ListSelectionEvent发送给监听器有一个source属性设置为此列表。
listener -
ListSelectionListener添加
getSelectionModel() ,
getListSelectionListeners()
public void removeListSelectionListener(ListSelectionListener listener)
listener - 要删除的
ListSelectionListener
addListSelectionListener(javax.swing.event.ListSelectionListener) ,
getSelectionModel()
public ListSelectionListener[] getListSelectionListeners()
ListSelectionListener加入到这个S
JList途经
addListSelectionListener 。
ListSelectionListener ,或者如果没有添加侦听器,则为空数组
addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setSelectionModel(ListSelectionModel selectionModel)
selectionModel设置为非null ListSelectionModel实现。
选择模型处理单个选择,连续范围的选择以及不连续选择的任务。
这是一个JavaBeans绑定属性。
selectionModel -在
ListSelectionModel实现的选择
IllegalArgumentException - 如果
selectionModel是
null
getSelectionModel()
public void setSelectionMode(int selectionMode)
以下列表描述了接受的选择模式:
ListSelectionModel.SINGLE_SELECTION - 一次只能选择一个列表索引。 在这种模式下, setSelectionInterval和addSelectionInterval是等价的,都用当前选择代替第二个参数(“lead”)表示的索引。 ListSelectionModel.SINGLE_INTERVAL_SELECTION - 一次只能选择一个连续的间隔。 在此模式下, addSelectionInterval行为类似于setSelectionInterval (替换当前选择),除非给定的间隔与现有选择紧密相邻或重叠,并可用于增加选择。 ListSelectionModel.MULTIPLE_INTERVAL_SELECTION - 在这种模式下,对什么可以选择没有限制。 此模式是默认模式。 selectionMode - 选择模式
IllegalArgumentException - 如果选择模式不是允许的模式之一
getSelectionMode()
public int getSelectionMode()
setSelectionMode(int)
public int getAnchorSelectionIndex()
ListSelectionModel.getAnchorSelectionIndex()
public int getLeadSelectionIndex()
ListSelectionModel.getLeadSelectionIndex()
public int getMinSelectionIndex()
-1引,如果选择为空,则返回-1。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
-1
ListSelectionModel.getMinSelectionIndex()
public int getMaxSelectionIndex()
-1引,如果选择为空,则返回-1。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
ListSelectionModel.getMaxSelectionIndex()
public boolean isSelectedIndex(int index)
true ,否则为false 。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
index - 要查询选择状态的索引
true如果指定的索引被选中,否则为
false
ListSelectionModel.isSelectedIndex(int) ,
setSelectedIndex(int)
public boolean isSelectionEmpty()
true ,否则false 。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
true如果没有选择,否则
false
ListSelectionModel.isSelectionEmpty() ,
clearSelection()
public void clearSelection()
isSelectionEmpty将返回true 。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
public void setSelectionInterval(int anchor,
int lead)
anchor和lead指数。
anchor不一定要小于或等于lead 。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
有关如何处理小于0值的详细信息,请参阅所选模型类的0 。
anchor - 第一个要选择的索引
lead - 最后选择的索引
ListSelectionModel.setSelectionInterval(int, int) ,
DefaultListSelectionModel.setSelectionInterval(int, int) ,
createSelectionModel() ,
addSelectionInterval(int, int) ,
removeSelectionInterval(int, int)
public void addSelectionInterval(int anchor,
int lead)
anchor和lead指数。
anchor不一定要小于或等于lead 。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
有关如何处理小于0值的详细信息,请参阅所选模型类的0 。
anchor - 添加到选择的第一个索引
lead - 添加到选择的最后一个索引
ListSelectionModel.addSelectionInterval(int, int) ,
DefaultListSelectionModel.addSelectionInterval(int, int) ,
createSelectionModel() ,
setSelectionInterval(int, int) ,
removeSelectionInterval(int, int)
public void removeSelectionInterval(int index0,
int index1)
index0和index1指数都被删除。
index0不得少于或等于index1 。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
有关如何处理小于0值的详细信息,请参阅所选模型类的0 。
index0 - 从选择中删除的第一个索引
index1 - 从选择中删除的最后一个索引
ListSelectionModel.removeSelectionInterval(int, int) ,
DefaultListSelectionModel.removeSelectionInterval(int, int) ,
createSelectionModel() ,
setSelectionInterval(int, int) ,
addSelectionInterval(int, int)
public void setValueIsAdjusting(boolean b)
valueIsAdjusting属性。
当true ,即将到来的选择变化应该被认为是单一变化的一部分。
此属性在内部使用,开发人员通常不需要调用此方法。
例如,当模型正在更新以响应用户拖动时,当拖动被启动时,该属性的值被设置为true ,并且在拖动完成时设置为false 。
这允许监听器仅在更改已经完成时进行更新,而不是处理所有中间值。
如果进行一系列更改,那么您可能需要直接使用它,这些更改应被视为单个更改的一部分。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。 有关详细信息,请参阅ListSelectionModel.setValueIsAdjusting(boolean)的文档 。
public boolean getValueIsAdjusting()
isAdjusting属性的值。
这是一种覆盖方法,委托给列表选择模型上相同名称的方法。
isAdjusting属性。
setValueIsAdjusting(boolean) ,
ListSelectionModel.getValueIsAdjusting()
public int[] getSelectedIndices()
removeSelectionInterval(int, int) ,
addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setSelectedIndex(int index)
setSelectionInterval的方便方法。
有关如何处理小于0值的详细信息,请参阅所选模型类的0 。
index - 要选择的单元格的索引
ListSelectionModel.setSelectionInterval(int, int) ,
isSelectedIndex(int) ,
addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setSelectedIndices(int[] indices)
addSelectionInterval添加索引。
有关如何处理小于0值的详细信息,请参阅所选模型类的0 。
indices - 要选择的单元格的索引的数组,
non-null
NullPointerException - 如果给定的数组是
null
ListSelectionModel.addSelectionInterval(int, int) ,
isSelectedIndex(int) ,
addListSelectionListener(javax.swing.event.ListSelectionListener)
@Deprecated public Object[] getSelectedValues()
getSelectedValuesList()取代
isSelectedIndex(int) ,
getModel() ,
addListSelectionListener(javax.swing.event.ListSelectionListener)
public List<E> getSelectedValuesList()
isSelectedIndex(int) ,
getModel() ,
addListSelectionListener(javax.swing.event.ListSelectionListener)
public int getSelectedIndex()
-1如果没有选择。
这种方法是一个委托给getMinSelectionIndex 。
getMinSelectionIndex() ,
addListSelectionListener(javax.swing.event.ListSelectionListener)
public E getSelectedValue()
null如果没有选择。
这是一个方便的方法,只需返回getMinSelectionIndex的模型值。
public void setSelectedValue(Object anObject, boolean shouldScroll)
anObject - 要选择的对象
shouldScroll - true如果列表滚动显示所选对象,如果存在;
否则false
public Dimension getPreferredScrollableViewportSize()
visibleRowCount行所需的视口大小。
此方法返回的值取决于布局方向:
VERTICAL :
如果已经设置了fixedCellWidth和fixedCellHeight (显式地或通过指定原型单元格值),这是微不足道的。 宽度只是fixedCellWidth加上列表的水平插图。 高度是fixedCellHeight乘以visibleRowCount ,加上列表的垂直插图。
如果没有fixedCellWidth或fixedCellHeight ,则使用启发式。 如果模型为空,则宽度为fixedCellWidth ,如果大于0 ,或硬编码值为256 。 高度是fixedCellHeight乘以visibleRowCount ,如果fixedCellHeight大于0 ,否则是硬编码值16乘以visibleRowCount 。
如果模型不为空,则宽度是首选大小的宽度,通常是最宽列表元素的宽度。 高度是fixedCellHeight乘以visibleRowCount ,加上列表的垂直插图。
VERTICAL_WRAP或HORIZONTAL_WRAP :
此方法只返回值为getPreferredSize 。 该列表的ListUI预计将覆盖getPreferredSize以返回适当的值。
getPreferredScrollableViewportSize在接口
Scrollable
visibleRowCount行所需视口大小的
visibleRowCount
getPreferredScrollableViewportSize() ,
setPrototypeCellValue(E)
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
对于水平滚动,如果布局方向为VERTICAL ,则列表的字体大小被返回(或1如果字体为null )。
getScrollableUnitIncrement中的
Scrollable
visibleRect - 在视口内可见的视图区域
orientation -
SwingConstants.HORIZONTAL或
SwingConstants.VERTICAL
direction - 向上/向下滚动小于或等于零,向下/向前大于零
IllegalArgumentException - 如果
visibleRect是
null ,或
orientation不是
SwingConstants.VERTICAL或
SwingConstants.HORIZONTAL
getScrollableBlockIncrement(java.awt.Rectangle, int, int) ,
Scrollable.getScrollableUnitIncrement(java.awt.Rectangle, int, int)
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
对于垂直滚动,使用以下规则:
visibleRect.height 对于水平滚动,当布局方向为VERTICAL_WRAP或HORIZONTAL_WRAP :
visibleRect.width 对于水平滚动和VERTICAL方向,返回visibleRect.width 。
请注意, visibleRect的值必须等于this.getVisibleRect() 。
getScrollableBlockIncrement在接口
Scrollable
visibleRect - 在视口内可见的视图区域
orientation -
SwingConstants.HORIZONTAL或
SwingConstants.VERTICAL
direction - 向上/向后滚动小于或等于零,大于零用于向下/向前
IllegalArgumentException - 如果
visibleRect是
null ,或
orientation不是
SwingConstants.VERTICAL或
SwingConstants.HORIZONTAL
getScrollableUnitIncrement(java.awt.Rectangle, int, int) ,
Scrollable.getScrollableBlockIncrement(java.awt.Rectangle, int, int)
public boolean getScrollableTracksViewportWidth()
true如果此JList被显示在JViewport和视口比所述列表的优选宽度,或者如果布局方向为HORIZONTAL_WRAP和visibleRowCount <= 0 ;
否则返回false 。
如果false ,那么不要跟踪视口的宽度。 如果JViewport本身嵌入在一个JScrollPane则允许水平JScrollPane 。
getScrollableTracksViewportWidth在接口
Scrollable
Scrollable.getScrollableTracksViewportWidth()
public boolean getScrollableTracksViewportHeight()
true如果JList显示在JViewport和视口比列表的首选高度更高,或者布局方向为VERTICAL_WRAP和visibleRowCount <= 0 ;
否则返回false 。
如果false ,那么不要跟踪视口的高度。 如果JViewport本身嵌入在一个JScrollPane则允许垂直JScrollPane 。
getScrollableTracksViewportHeight在接口
Scrollable
Scrollable.getScrollableTracksViewportHeight()
protected String paramString()
String如此表示JList 。
该方法仅用于调试目的,并且返回的String的内容和格式可能因实现而异。
返回的String可能为空,但可能不是null 。
paramString在
JComponent
String表示这个
JList 。
public AccessibleContext getAccessibleContext()
AccessibleContext与此相关JList 。
为JList ,所述AccessibleContext需要一个的形式AccessibleJList 。
如有必要,将创建一个新的AccessibleJList实例。
getAccessibleContext在界面
Accessible
getAccessibleContext在
Component
AccessibleJList ,作为这个
AccessibleContext的
JList
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.