- java.lang.Object
-
- java.awt.Component
-
- java.awt.List
-
- 实现的所有接口
-
ImageObserver,ItemSelectable,MenuContainer,Serializable,Accessible
public class List extends Component implements ItemSelectable, Accessible
List组件向用户显示文本项的滚动列表。 可以设置列表,以便用户可以选择一个项目或多个项目。例如,代码。 。 。
List lst = new List(4, false); lst.add("Mercury"); lst.add("Venus"); lst.add("Earth"); lst.add("JavaSoft"); lst.add("Mars"); lst.add("Jupiter"); lst.add("Saturn"); lst.add("Uranus"); lst.add("Neptune"); lst.add("Pluto"); cnt.add(lst);
其中
cnt是一个容器,产生以下滚动列表:
如果列表允许多个选择,则单击已选择的项目将取消选择它。 在前面的示例中,一次只能选择滚动列表中的一个项目,因为创建新滚动列表时的第二个参数是
false。 如果列表不允许多个选择,则选择项目会导致取消选择任何其他所选项目。请注意,显示的示例中的列表是使用四个可见行创建的。 创建列表后,无法更改可见行数。 创建默认值
List,其中包含四行,因此lst = new List()等效于list = new List(4, false)。从Java 1.1开始,Abstract Window Toolkit向
List对象发送在其上List所有鼠标,键盘和焦点事件。 (旧的AWT事件模型仅用于向后兼容,并且不鼓励使用它。)当用户选择或取消选择某个项目时,AWT会向列表发送
ItemEvent的实例。 当用户双击滚动列表中的项目时,AWT会在项目事件后面的列表中发送ActionEvent的实例。 当用户在选择列表中的项目时按下返回键时,AWT也会生成一个动作事件。如果应用程序想要根据用户选择或激活此列表中的项目执行某些操作,则应根据需要实施
ItemListener或ActionListener并注册新侦听器以从此列表接收事件。对于多选滚动列表,使用外部手势(例如单击按钮)来触发操作被认为是更好的用户界面。
- 从以下版本开始:
- 1.0
- 另请参见:
-
ItemEvent,ItemListener,ActionEvent,ActionListener, Serialized Form
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 protected classList.AccessibleAWTList此类实现List类的可访问性支持。
-
字段汇总
-
声明的属性在类 java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
方法摘要
所有方法 实例方法 具体的方法 弃用的方法 变量和类型 方法 描述 voidadd(String item)将指定的项添加到滚动列表的末尾。voidadd(String item, int index)将指定的项添加到索引指示的位置的滚动列表中。voidaddActionListener(ActionListener l)添加指定的操作侦听器以从此列表接收操作事件。voidaddItem(String item)已过时。由add(String)取代。voidaddItem(String item, int index)已过时。由add(String, int)取代。voidaddItemListener(ItemListener l)添加指定的项侦听器以从此列表接收项事件。voidaddNotify()创建列表的对等方。booleanallowsMultipleSelections()已过时。截至JDK 1.1版,由isMultipleMode()取代。voidclear()已过时。截至JDK 1.1版,由removeAll()取代。intcountItems()已过时。截至JDK 1.1版,由getItemCount()取代。voiddelItem(int position)已过时。由remove(String)和remove(int)取代。voiddelItems(int start, int end)已过时。从JDK 1.1版开始,未来不会公开使用。voiddeselect(int index)取消选择指定索引处的项目。AccessibleContextgetAccessibleContext()获取与AccessibleContext相关的List。ActionListener[]getActionListeners()返回在此列表中注册的所有动作侦听器的数组。StringgetItem(int index)获取与指定索引关联的项。intgetItemCount()获取列表中的项目数。ItemListener[]getItemListeners()返回在此列表中注册的所有项侦听器的数组。String[]getItems()获取列表中的项目。<T extends EventListener>
T[]getListeners(类<T> listenerType)返回当前注册的所有对象的数组FooListener在这个SList。DimensiongetMinimumSize()确定此滚动列表的最小大小。DimensiongetMinimumSize(int rows)获取具有指定行数的列表的最小尺寸。DimensiongetPreferredSize()获取此滚动列表的首选大小。DimensiongetPreferredSize(int rows)获取具有指定行数的列表的首选维度。intgetRows()获取此列表中可见行的数量。intgetSelectedIndex()获取列表中所选项的索引,int[]getSelectedIndexes()获取列表中的选定索引。StringgetSelectedItem()获取此滚动列表中的选定项。String[]getSelectedItems()获取此滚动列表中的选定项。Object[]getSelectedObjects()获取对象数组中此滚动列表中的选定项。intgetVisibleIndex()获取方法makeVisible最后可见的项的索引。booleanisIndexSelected(int index)确定是否选择了此滚动列表中的指定项。booleanisMultipleMode()确定此列表是否允许多个选择。booleanisSelected(int index)已过时。截至JDK 1.1版,由isIndexSelected(int)取代。voidmakeVisible(int index)使指定索引处的项目可见。DimensionminimumSize()已过时。截至JDK 1.1版,由getMinimumSize()取代。DimensionminimumSize(int rows)已过时。截至JDK 1.1版,由getMinimumSize(int)取代。protected StringparamString()返回表示此滚动列表状态的参数字符串。DimensionpreferredSize()已过时。截至JDK 1.1版,由getPreferredSize()取代。DimensionpreferredSize(int rows)已过时。截至JDK 1.1版,由getPreferredSize(int)取代。protected voidprocessActionEvent(ActionEvent e)处理在此组件上发生的操作事件,方法是将它们分派给任何已注册的ActionListener对象。protected voidprocessEvent(AWTEvent e)处理此滚动列表上的事件。protected voidprocessItemEvent(ItemEvent e)处理此列表上发生的项目事件,方法是将它们分派给任何已注册的ItemListener对象。voidremove(int position)从此滚动列表中删除指定位置的项目。voidremove(String item)从列表中删除第一个项目。voidremoveActionListener(ActionListener l)删除指定的操作侦听器,以便它不再从此列表中接收操作事件。voidremoveAll()从此列表中删除所有项目。voidremoveItemListener(ItemListener l)删除指定的项侦听器,以便它不再从此列表中接收项事件。voidremoveNotify()删除此列表的对等项。voidreplaceItem(String newValue, int index)使用新字符串替换滚动列表中指定索引处的项目。voidselect(int index)选择滚动列表中指定索引处的项目。voidsetMultipleMode(boolean b)设置标志以确定此列表是否允许多个选择。voidsetMultipleSelections(boolean b)已过时。截至JDK 1.1版,由setMultipleMode(boolean)取代。-
声明方法的类 java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
-
-
-
构造方法详细信息
-
List
public List() throws HeadlessException创建一个新的滚动列表。 默认情况下,有四条可见行,不允许多个选择。 请注意,这是List(0, false)的便捷方法。 另请注意,列表中的可见行数在创建后无法更改。- 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless()返回true。 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
List
public List(int rows) throws HeadlessException创建使用指定数量的可见行初始化的新滚动列表。 默认情况下,不允许多个选择。 请注意,这是List(rows, false)的便捷方法。 另请注意,列表中的可见行数在创建后无法更改。- 参数
-
rows- 要显示的项目数。 - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless()返回true。 - 从以下版本开始:
- 1.1
- 另请参见:
-
GraphicsEnvironment.isHeadless()
-
List
public List(int rows, boolean multipleMode) throws HeadlessException创建一个初始化的新滚动列表,以显示指定的行数。 请注意,如果指定了零行,则将使用默认的四行创建列表。 另请注意,列表中的可见行数在创建后无法更改。 如果multipleMode的值是true,则用户可以从列表中选择多个项目。 如果是false,则false只能选择一个项目。- 参数
-
rows- 要显示的项目数。 -
multipleMode- 如果是true,则允许多个选择; 否则,一次只能选择一个项目。 - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless()返回true。 - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
-
方法详细信息
-
addNotify
public void addNotify()
创建列表的对等方。 对等体允许我们在不改变其功能的情况下修改列表的外观。
-
removeNotify
public void removeNotify()
删除此列表的对等项。 对等体允许我们在不改变其功能的情况下修改列表的外观。
-
getItemCount
public int getItemCount()
获取列表中的项目数。- 结果
- 列表中的项目数
- 从以下版本开始:
- 1.1
- 另请参见:
-
getItem(int)
-
countItems
@Deprecated public int countItems()
Deprecated.As of JDK version 1.1, replaced bygetItemCount().返回列表中的项目数。- 结果
- 列表中的项目数
-
getItem
public String getItem(int index)
获取与指定索引关联的项。- 参数
-
index- 项目的位置 - 结果
- 与指定索引关联的项目
- 另请参见:
-
getItemCount()
-
getItems
public String[] getItems()
获取列表中的项目。- 结果
- 包含列表项的字符串数组
- 从以下版本开始:
- 1.1
- 另请参见:
-
select(int),deselect(int),isIndexSelected(int)
-
add
public void add(String item)
将指定的项添加到滚动列表的末尾。- 参数
-
item- 要添加的项目 - 从以下版本开始:
- 1.1
-
addItem
@Deprecated public void addItem(String item)
Deprecated.replaced byadd(String).将指定的项添加到列表的末尾。- 参数
-
item- 要添加的项目
-
add
public void add(String item, int index)
将指定的项添加到索引指示的位置的滚动列表中。 该指数从零开始。 如果索引的值小于零,或者索引的值大于或等于列表中的项目数,则该项目将添加到列表的末尾。- 参数
-
item- 要添加的项目; 如果此参数为null则该项目将被视为空字符串,"" -
index- 添加项目的位置 - 从以下版本开始:
- 1.1
-
addItem
@Deprecated public void addItem(String item, int index)
Deprecated.replaced byadd(String, int).将指定项添加到索引所指示位置的列表中。- 参数
-
item- 要添加的项目 -
index- 添加项目的位置
-
replaceItem
public void replaceItem(String newValue, int index)
使用新字符串替换滚动列表中指定索引处的项目。- 参数
-
newValue- 用于替换现有项目的新字符串 -
index- 要替换的项目的位置 - 异常
-
ArrayIndexOutOfBoundsException- 如果index超出范围
-
removeAll
public void removeAll()
从此列表中删除所有项目。- 从以下版本开始:
- 1.1
- 另请参见:
-
remove(java.lang.String),delItems(int, int)
-
clear
@Deprecated public void clear()
Deprecated.As of JDK version 1.1, replaced byremoveAll().
-
remove
public void remove(String item)
从列表中删除第一个项目。 如果选择了指定的项目,并且该列表是列表中唯一选定的项目,则列表将设置为无选择。- 参数
-
item- 要从列表中删除的项目 - 异常
-
IllegalArgumentException- 如果列表中不存在该项目 - 从以下版本开始:
- 1.1
-
remove
public void remove(int position)
从此滚动列表中删除指定位置的项目。 如果选择了具有指定位置的项目,并且该项目是列表中唯一选定的项目,则列表将设置为无选择。- 参数
-
position- 要删除的项目的索引 - 异常
-
ArrayIndexOutOfBoundsException- 如果position小于0或大于getItemCount()-1 - 从以下版本开始:
- 1.1
- 另请参见:
-
add(String, int)
-
delItem
@Deprecated public void delItem(int position)
Deprecated.replaced byremove(String)andremove(int).删除指定位置的项目。- 参数
-
position- 要删除的项目的索引
-
getSelectedIndex
public int getSelectedIndex()
获取列表中所选项的索引,- 结果
-
所选项目的索引;
如果未选择任何项目,或者如果选择了多个项目,则返回
-1。 - 另请参见:
-
select(int),deselect(int),isIndexSelected(int)
-
getSelectedIndexes
public int[] getSelectedIndexes()
获取列表中的选定索引。- 结果
- 此滚动列表中所选索引的数组; 如果未选择任何项,则返回零长度数组。
- 另请参见:
-
select(int),deselect(int),isIndexSelected(int)
-
getSelectedItem
public String getSelectedItem()
获取此滚动列表中的选定项。- 结果
-
列表中的选定项目;
如果未选择任何项目,或者选择了多个项目,则返回
null。 - 另请参见:
-
select(int),deselect(int),isIndexSelected(int)
-
getSelectedItems
public String[] getSelectedItems()
获取此滚动列表中的选定项。- 结果
- 此滚动列表中所选项目的数组; 如果未选择任何项,则返回零长度数组。
- 另请参见:
-
select(int),deselect(int),isIndexSelected(int)
-
getSelectedObjects
public Object[] getSelectedObjects()
获取对象数组中此滚动列表中的选定项。- Specified by:
-
getSelectedObjects在接口ItemSelectable - 结果
-
表示此滚动列表中所选项目的
Object数组; 如果未选择任何项,则返回零长度数组。 - 另请参见:
-
getSelectedItems(),ItemSelectable
-
select
public void select(int index)
选择滚动列表中指定索引处的项目。请注意,传出范围参数无效,并将导致未指定的行为。
请注意,此方法应主要用于初始选择此组件中的项目。 以编程方式调用此方法不会触发
ItemEvent。 触发ItemEvent的唯一方法是通过用户交互。- 参数
-
index- 要选择的项目的位置 - 另请参见:
-
getSelectedItem(),deselect(int),isIndexSelected(int)
-
deselect
public void deselect(int index)
取消选择指定索引处的项目。请注意,传出范围参数无效,并将导致未指定的行为。
如果未选择指定索引处的项目,则忽略该操作。
- 参数
-
index- 要取消选择的项目的位置 - 另请参见:
-
select(int),getSelectedItem(),isIndexSelected(int)
-
isIndexSelected
public boolean isIndexSelected(int index)
确定是否选择了此滚动列表中的指定项。- 参数
-
index- 要检查的项目 - 结果
-
true如果已选择指定的项目; 否则为false - 从以下版本开始:
- 1.1
- 另请参见:
-
select(int),deselect(int)
-
isSelected
@Deprecated public boolean isSelected(int index)
Deprecated.As of JDK version 1.1, replaced byisIndexSelected(int).确定是否选择了列表中的指定项。- 参数
-
index- 指定要检查的项目 - 结果
-
true如果选择了该项目; 否则false
-
getRows
public int getRows()
获取此列表中可见行的数量。 请注意,创建List,此数字将永远不会更改。- 结果
- 此滚动列表中的可见行数
-
isMultipleMode
public boolean isMultipleMode()
确定此列表是否允许多个选择。- 结果
-
true如果此列表允许多个选择; 否则,false - 从以下版本开始:
- 1.1
- 另请参见:
-
setMultipleMode(boolean)
-
allowsMultipleSelections
@Deprecated public boolean allowsMultipleSelections()
Deprecated.As of JDK version 1.1, replaced byisMultipleMode().确定此列表是否允许多个选择。- 结果
-
true如果此列表允许多个选择; 否则false
-
setMultipleMode
public void setMultipleMode(boolean b)
设置标志以确定此列表是否允许多个选择。 当选择模式从多选改变为单选时,所选项改变如下:如果所选项具有位置光标,则仅保留选择该项。 如果没有选定项目具有位置光标,则将取消选择所有项目。- 参数
-
b- 如果true则允许多个选择; 否则,一次只能选择列表中的一个项目 - 从以下版本开始:
- 1.1
- 另请参见:
-
isMultipleMode()
-
setMultipleSelections
@Deprecated public void setMultipleSelections(boolean b)
Deprecated.As of JDK version 1.1, replaced bysetMultipleMode(boolean).启用或禁用此列表的多选模式。- 参数
-
b-true启用多种模式,否则为false
-
getVisibleIndex
public int getVisibleIndex()
获取方法makeVisible最后可见的项的索引。- 结果
- 上次可见的项目的索引
- 另请参见:
-
makeVisible(int)
-
makeVisible
public void makeVisible(int index)
使指定索引处的项目可见。- 参数
-
index- 项目的位置 - 另请参见:
-
getVisibleIndex()
-
getPreferredSize
public Dimension getPreferredSize(int rows)
获取具有指定行数的列表的首选维度。- 参数
-
rows- 列表中的行数 - 结果
- 给定指定行数必须可见的显示此滚动列表的首选尺寸
- 从以下版本开始:
- 1.1
- 另请参见:
-
Component.getPreferredSize()
-
preferredSize
@Deprecated public Dimension preferredSize(int rows)
Deprecated.As of JDK version 1.1, replaced bygetPreferredSize(int).假设它具有指定的行数,则返回此组件的首选大小。- 参数
-
rows- 行数 - 结果
- 显示此列表的首选尺寸
-
getPreferredSize
public Dimension getPreferredSize()
获取此滚动列表的首选大小。- 重写:
-
getPreferredSize类Component - 结果
- 显示此滚动列表的首选尺寸
- 从以下版本开始:
- 1.1
- 另请参见:
-
Component.getPreferredSize()
-
preferredSize
@Deprecated public Dimension preferredSize()
Deprecated.As of JDK version 1.1, replaced bygetPreferredSize().复制自类:Component描述返回组件的首选大小。- 重写:
-
preferredSize,类Component - 结果
- 组件的首选大小
-
getMinimumSize
public Dimension getMinimumSize(int rows)
获取具有指定行数的列表的最小尺寸。- 参数
-
rows- 列表中的行数 - 结果
- 给定指定行数必须可见的显示此滚动列表的最小尺寸
- 从以下版本开始:
- 1.1
- 另请参见:
-
Component.getMinimumSize()
-
minimumSize
@Deprecated public Dimension minimumSize(int rows)
Deprecated.As of JDK version 1.1, replaced bygetMinimumSize(int).返回具有指定行数的列表的最小尺寸。- 参数
-
rows- 列表中的行数 - 结果
- 显示此列表的最小尺寸
-
getMinimumSize
public Dimension getMinimumSize()
确定此滚动列表的最小大小。- 重写:
-
getMinimumSize在类Component - 结果
- 显示此滚动列表所需的最小尺寸
- 从以下版本开始:
- 1.1
- 另请参见:
-
Component.getMinimumSize()
-
minimumSize
@Deprecated public Dimension minimumSize()
Deprecated.As of JDK version 1.1, replaced bygetMinimumSize().返回此组件的最小大小。- 重写:
-
minimumSize类Component - 结果
- 此组件的最小大小
-
addItemListener
public void addItemListener(ItemListener l)
添加指定的项侦听器以从此列表接收项事件。 项目事件是响应用户输入发送的,但不响应对select或deselect调用。 如果监听器l是null,则不抛出任何异常并且不执行任何操作。有关AWT螺纹模型的详细信息,请参阅AWT Threading Issues 。
- Specified by:
-
addItemListener在接口ItemSelectable - 参数
-
l- 项侦听器 - 从以下版本开始:
- 1.1
- 另请参见:
-
removeItemListener(java.awt.event.ItemListener),getItemListeners(),select(int),deselect(int),ItemEvent,ItemListener
-
removeItemListener
public void removeItemListener(ItemListener l)
- Specified by:
-
removeItemListener在接口ItemSelectable - 参数
-
l- 项侦听器 - 从以下版本开始:
- 1.1
- 另请参见:
-
addItemListener(java.awt.event.ItemListener),getItemListeners(),ItemEvent,ItemListener
-
getItemListeners
public ItemListener[] getItemListeners()
返回在此列表中注册的所有项侦听器的数组。- 结果
-
所有这个列表的
ItemListener或如果当前没有注册项目监听器的空数组 - 从以下版本开始:
- 1.4
- 另请参见:
-
addItemListener(java.awt.event.ItemListener),removeItemListener(java.awt.event.ItemListener),ItemEvent,ItemListener
-
addActionListener
public void addActionListener(ActionListener l)
添加指定的操作侦听器以从此列表接收操作事件。 当用户双击列表项时会发生操作事件,或者当列表具有键盘焦点时键入Enter。如果监听器
l是null,则不会抛出异常并且不执行任何操作。有关AWT螺纹模型的详细信息,请参阅AWT Threading Issues 。
- 参数
-
l- 动作侦听器 - 从以下版本开始:
- 1.1
- 另请参见:
-
removeActionListener(java.awt.event.ActionListener),getActionListeners(),ActionEvent,ActionListener
-
removeActionListener
public void removeActionListener(ActionListener l)
删除指定的操作侦听器,以便它不再从此列表中接收操作事件。 当用户双击列表项时,会发生操作事件。 如果监听器l是null,则不抛出任何异常并且不执行任何操作。有关AWT螺纹模型的详细信息,请参阅AWT Threading Issues 。
- 参数
-
l- 动作侦听器 - 从以下版本开始:
- 1.1
- 另请参见:
-
addActionListener(java.awt.event.ActionListener),getActionListeners(),ActionEvent,ActionListener
-
getActionListeners
public ActionListener[] getActionListeners()
返回在此列表中注册的所有动作侦听器的数组。- 结果
-
如果当前没有注册动作侦听器,则此列表的所有内容为
ActionListener或空数组 - 从以下版本开始:
- 1.4
- 另请参见:
-
addActionListener(java.awt.event.ActionListener),removeActionListener(java.awt.event.ActionListener),ActionEvent,ActionListener
-
getListeners
public <T extends EventListener> T[] getListeners(类<T> listenerType)
返回当前注册的所有对象的数组FooListener在这个SList。FooListeners使用addFooListener方法注册。您可以使用类文字指定
listenerType参数,例如FooListener.class。 例如,您可以使用以下代码在List l查询其项侦听器:ItemListener[] ils = (ItemListener[])(l.getListeners(ItemListener.class));如果不存在此类侦听器,则此方法返回空数组。- 重写:
-
getListeners在类Component - 参数类型
-
T- 侦听器的类型 - 参数
-
listenerType- 请求的侦听器类型; 此参数应指定从java.util.EventListener下降的接口 - 结果
-
此列表中注册为
FooListener的所有对象的数组,如果未添加此类侦听器,则为空数组 - 异常
-
ClassCastException- 如果listenerType未指定实现java.util.EventListener的类或接口 - 从以下版本开始:
- 1.3
- 另请参见:
-
getItemListeners()
-
processEvent
protected void processEvent(AWTEvent e)
处理此滚动列表上的事件。 如果事件是ItemEvent的实例,则它将调用processItemEvent方法。 否则,如果事件是ActionEvent的实例,则调用processActionEvent。 如果事件不是项事件或动作事件,则在超类上调用processEvent。请注意,如果事件参数为
null则行为未指定,可能会导致异常。- 重写:
-
processEvent类Component - 参数
-
e- 此活动 - 从以下版本开始:
- 1.1
- 另请参见:
-
ActionEvent,ItemEvent,processActionEvent(java.awt.event.ActionEvent),processItemEvent(java.awt.event.ItemEvent)
-
processItemEvent
protected void processItemEvent(ItemEvent e)
处理此列表上发生的项目事件,方法是将它们分派给任何已注册的ItemListener对象。除非为此组件启用了项事件,否则不会调用此方法。 发生以下任一情况时启用项目事件:
-
ItemListener对象通过addItemListener注册。 - 项目事件通过
enableEvents启用。
请注意,如果事件参数为
null则行为未指定,可能会导致异常。- 参数
-
e- 项目事件 - 从以下版本开始:
- 1.1
- 另请参见:
-
ItemEvent,ItemListener,addItemListener(java.awt.event.ItemListener),Component.enableEvents(long)
-
-
processActionEvent
protected void processActionEvent(ActionEvent e)
处理在此组件上发生的操作事件,方法是将它们分派给任何已注册的ActionListener对象。除非为此组件启用了操作事件,否则不会调用此方法。 发生以下任一情况时启用操作事件:
-
ActionListener对象通过addActionListener注册。 - 通过
enableEvents启用操作事件。
请注意,如果事件参数为
null则行为未指定,可能会导致异常。- 参数
-
e- 动作事件 - 从以下版本开始:
- 1.1
- 另请参见:
-
ActionEvent,ActionListener,addActionListener(java.awt.event.ActionListener),Component.enableEvents(long)
-
-
paramString
protected String paramString()
返回表示此滚动列表状态的参数字符串。 此字符串对调试很有用。- 重写:
-
paramString类Component - 结果
- 此滚动列表的参数字符串
-
delItems
@Deprecated public void delItems(int start, int end)
Deprecated.As of JDK version 1.1, Not for public use in the future. This method is expected to be retained only as a package private method.删除指定索引范围内的列表项。- 参数
-
start- 要删除的范围的起始索引 -
end- 要删除的范围的结束索引
-
getAccessibleContext
public AccessibleContext getAccessibleContext()
获取与AccessibleContext相关的List。 对于名单中,AccessibleContext需要一个形式AccessibleAWTList。 如有必要,将创建一个新的AccessibleAWTList实例。- Specified by:
-
getAccessibleContext,接口Accessible - 重写:
-
getAccessibleContext在类Component - 结果
-
AccessibleAWTList,作为AccessibleContext的List - 从以下版本开始:
- 1.3
-
-