public class FocusEvent extends ComponentEvent
addFocusListener方法注册接收此类事件的每个FocusListener或FocusAdapter对象。
( FocusAdapter对象实现FocusListener接口。)每个这样的侦听器对象在事件发生时得到这个FocusEvent 。
焦点事件有两个层次:永久性和临时性。 当焦点直接从一个组件移动到另一个组件时,例如通过调用requestFocus()或用户使用TAB键遍历组件时,会发生永久性焦点更改事件。 当组件临时丢失焦点作为另一个操作的间接结果(如窗口停用或滚动条拖动)时,会发生临时焦点更改事件。 在这种情况下,一旦操作完成,原始对焦状态就会自动恢复,或者在Windows停用的情况下,当窗口重新启动时。 永久和临时焦点事件都使用FOCUS_GAINED和FOCUS_LOST事件ID进行传送; 在使用isTemporary()方法的情况下,可以区分该级别。
如果未指定的行为将引起id任何特定的参数FocusEvent实例不在范围从FOCUS_FIRST到FOCUS_LAST 。
FocusAdapter , FocusListener , Tutorial: Writing a Focus Listener , Serialized Form
| Modifier and Type | Field and Description |
|---|---|
static int |
FOCUS_FIRST
用于焦点事件的ids范围中的第一个数字。
|
static int |
FOCUS_GAINED
此事件表示组件现在是焦点所有者。
|
static int |
FOCUS_LAST
用于焦点事件的ids范围中的最后一个数字。
|
static int |
FOCUS_LOST
此事件表示组件不再是焦点所有者。
|
COMPONENT_FIRST, COMPONENT_HIDDEN, COMPONENT_LAST, COMPONENT_MOVED, COMPONENT_RESIZED, COMPONENT_SHOWNACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, consumed, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, id, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASKsource| Constructor and Description |
|---|
FocusEvent(Component source, int id)
构造一个
FocusEvent对象,并将其标识为焦点的永久变化。
|
FocusEvent(Component source, int id, boolean temporary)
构造一个
FocusEvent对象,并确定更改是否是临时的。
|
FocusEvent(Component source, int id, boolean temporary, Component opposite)
构造具有
FocusEvent临时状态的
FocusEvent对象,对齐于
Component 。
|
| Modifier and Type | Method and Description |
|---|---|
Component |
getOppositeComponent()
返回此焦点更改中涉及的其他组件。
|
boolean |
isTemporary()
将焦点更改事件标识为临时或永久。
|
String |
paramString()
返回标识此事件的参数字符串。
|
getComponentgetSourcepublic static final int FOCUS_FIRST
public static final int FOCUS_LAST
public static final int FOCUS_GAINED
public static final int FOCUS_LOST
public FocusEvent(Component source, int id, boolean temporary, Component opposite)
FocusEvent与指定的临时状态和相反的对象Component 。
相反的Component是另外Component涉及到这个焦点变化。
对于FOCUS_GAINED事件,这是失去焦点的Component 。
对于FOCUS_LOST事件,这是获得焦点的Component 。
如果使用本机应用程序发生此焦点更改,在不同的VM中使用Java应用程序,或者没有其他的Component ,那么相反的Component是null 。
此方法抛出IllegalArgumentException如果source是null 。
source -该
Component发起事件
id - 指示事件类型的整数。
有关允许值的信息,请参阅FocusEvent的类说明
temporary - 等于true如果焦点变化是暂时的;
false否则
opposite - 其他组件涉及到焦点更改,或
null
IllegalArgumentException - 如果
source等于
null
EventObject.getSource() ,
AWTEvent.getID() ,
isTemporary() ,
getOppositeComponent()
public FocusEvent(Component source, int id, boolean temporary)
FocusEvent对象,并确定更改是否是临时的。
此方法抛出IllegalArgumentException如果source是null 。
source -该
Component发起事件
id - 指示事件类型的整数。
有关允许值的信息,请参阅FocusEvent的类说明
temporary -等于true如果焦点更改是暂时的;
false否则
IllegalArgumentException - 如果
source等于
null
EventObject.getSource() ,
AWTEvent.getID() ,
isTemporary()
public FocusEvent(Component source, int id)
FocusEvent对象,并将其标识为一个永久的焦点变化。
此方法抛出IllegalArgumentException如果source是null 。
source -该
Component发起事件
id - 指示事件类型的整数。
有关允许值的信息,请参阅FocusEvent的类说明
IllegalArgumentException - 如果
source等于
null
EventObject.getSource() ,
AWTEvent.getID()
public boolean isTemporary()
true如果焦点变化是暂时的;
false否则
public Component getOppositeComponent()
public String paramString()
paramString在
ComponentEvent
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.