Class InputMethodEvent
- All Implemented Interfaces:
Serializable
public class InputMethodEvent extends AWTEvent
The text included with the input method event consists of two parts: committed text and composed text. Either part may be empty. The two parts together replace any uncommitted composed text sent in previous events, or the currently selected committed text. Committed text should be integrated into the text component's persistent data, it will not be sent again. Composed text may be sent repeatedly, with changes to reflect the user's editing operations. Committed text always precedes composed text.
- Since:
- 1.2
- See Also:
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
static final int |
CARET_POSITION_CHANGED |
The event type indicating a changed insertion point in input method text. |
static final int |
INPUT_METHOD_FIRST |
Marks the first integer id for the range of input method event ids. |
static final int |
INPUT_METHOD_LAST |
Marks the last integer id for the range of input method event ids. |
static final int |
INPUT_METHOD_TEXT_CHANGED |
The event type indicating changed input method text. |
Fields declared in class AWTEvent
ACTION_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_MASK | Modifier and Type | Field | Description |
|---|---|---|
static final long |
ACTION_EVENT_MASK |
The event mask for selecting action events. |
static final long |
ADJUSTMENT_EVENT_MASK |
The event mask for selecting adjustment events. |
static final long |
COMPONENT_EVENT_MASK |
The event mask for selecting component events. |
protected boolean |
consumed |
Controls whether or not the event is sent back down to the peer once the source has processed it - false means it's sent to the peer; true means it's not. |
static final long |
CONTAINER_EVENT_MASK |
The event mask for selecting container events. |
static final long |
FOCUS_EVENT_MASK |
The event mask for selecting focus events. |
static final long |
HIERARCHY_BOUNDS_EVENT_MASK |
The event mask for selecting hierarchy bounds events. |
static final long |
HIERARCHY_EVENT_MASK |
The event mask for selecting hierarchy events. |
protected int |
id |
The event's id. |
static final long |
INPUT_METHOD_EVENT_MASK |
The event mask for selecting input method events. |
static final long |
INVOCATION_EVENT_MASK |
The event mask for selecting invocation events. |
static final long |
ITEM_EVENT_MASK |
The event mask for selecting item events. |
static final long |
KEY_EVENT_MASK |
The event mask for selecting key events. |
static final long |
MOUSE_EVENT_MASK |
The event mask for selecting mouse events. |
static final long |
MOUSE_MOTION_EVENT_MASK |
The event mask for selecting mouse motion events. |
static final long |
MOUSE_WHEEL_EVENT_MASK |
The event mask for selecting mouse wheel events. |
static final long |
PAINT_EVENT_MASK |
The event mask for selecting paint events. |
static final int |
RESERVED_ID_MAX |
The maximum value for reserved AWT event IDs. |
static final long |
TEXT_EVENT_MASK |
The event mask for selecting text events. |
static final long |
WINDOW_EVENT_MASK |
The event mask for selecting window events. |
static final long |
WINDOW_FOCUS_EVENT_MASK |
The event mask for selecting window focus events. |
static final long |
WINDOW_STATE_EVENT_MASK |
The event mask for selecting window state events. |
Fields declared in class EventObject
source | Modifier and Type | Field | Description |
|---|---|---|
protected Object |
source |
The object on which the Event initially occurred. |
Constructor Summary
| Constructor | Description |
|---|---|
InputMethodEvent |
Constructs an InputMethodEvent with the specified source component, type, time, text, caret, and visiblePosition. |
InputMethodEvent |
Constructs an InputMethodEvent with the specified source component, type, caret, and visiblePosition. |
InputMethodEvent |
Constructs an InputMethodEvent with the specified source component, type, text, caret, and visiblePosition. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
consume() |
Consumes this event so that it will not be processed in the default manner by the source which originated it. |
TextHitInfo |
getCaret() |
Gets the caret. |
int |
getCommittedCharacterCount() |
Gets the number of committed characters in the text. |
AttributedCharacterIterator |
getText() |
Gets the combined committed and composed text. |
TextHitInfo |
getVisiblePosition() |
Gets the position that's most important to be visible. |
long |
getWhen() |
Returns the time stamp of when this event occurred. |
boolean |
isConsumed() |
Returns whether or not this event has been consumed. |
String |
paramString() |
Returns a parameter string identifying this event. |
Methods declared in class AWTEvent
getID, setSource, toString | Modifier and Type | Method | Description |
|---|---|---|
int |
getID() |
Returns the event type. |
void |
setSource |
Retargets an event to a new source. |
String |
toString() |
Returns a String representation of this object. |
Methods declared in class EventObject
getSource | Modifier and Type | Method | Description |
|---|---|---|
Object |
getSource() |
The object on which the Event initially occurred. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Field Details
INPUT_METHOD_FIRST
@Native public static final int INPUT_METHOD_FIRST
- See Also:
INPUT_METHOD_TEXT_CHANGED
@Native public static final int INPUT_METHOD_TEXT_CHANGED
- See Also:
CARET_POSITION_CHANGED
@Native public static final int CARET_POSITION_CHANGED
- See Also:
INPUT_METHOD_LAST
@Native public static final int INPUT_METHOD_LAST
- See Also:
Constructor Details
InputMethodEvent
public InputMethodEvent(Component source, int id, long when, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)
InputMethodEvent with the specified source component, type, time, text, caret, and visiblePosition. The offsets of caret and visiblePosition are relative to the current composed text; that is, the composed text within text if this is an INPUT_METHOD_TEXT_CHANGED event, the composed text within the text of the preceding INPUT_METHOD_TEXT_CHANGED event otherwise.
Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.
- Parameters:
-
source- the object where the event originated -
id- the event type -
when- a long integer that specifies the time the event occurred -
text- the combined committed and composed text, committed text first; must benullwhen the event type isCARET_POSITION_CHANGED; may benullforINPUT_METHOD_TEXT_CHANGEDif there's no committed or composed text -
committedCharacterCount- the number of committed characters in the text -
caret- the caret (a.k.a. insertion point);nullif there's no caret within current composed text -
visiblePosition- the position that's most important to be visible;nullif there's no recommendation for a visible position within current composed text - Throws:
-
IllegalArgumentException- ifidis not in the rangeINPUT_METHOD_FIRST..INPUT_METHOD_LAST; or if id isCARET_POSITION_CHANGEDandtextis notnull; or ifcommittedCharacterCountis not in the range0..(text.getEndIndex() - text.getBeginIndex()) -
IllegalArgumentException- ifsourceis null - Since:
- 1.4
InputMethodEvent
public InputMethodEvent(Component source, int id, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition)
InputMethodEvent with the specified source component, type, text, caret, and visiblePosition. The offsets of caret and visiblePosition are relative to the current composed text; that is, the composed text within text if this is an INPUT_METHOD_TEXT_CHANGED event, the composed text within the text of the preceding INPUT_METHOD_TEXT_CHANGED event otherwise. The time stamp for this event is initialized by invoking EventQueue.getMostRecentEventTime().
Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.
- Parameters:
-
source- the object where the event originated -
id- the event type -
text- the combined committed and composed text, committed text first; must benullwhen the event type isCARET_POSITION_CHANGED; may benullforINPUT_METHOD_TEXT_CHANGEDif there's no committed or composed text -
committedCharacterCount- the number of committed characters in the text -
caret- the caret (a.k.a. insertion point);nullif there's no caret within current composed text -
visiblePosition- the position that's most important to be visible;nullif there's no recommendation for a visible position within current composed text - Throws:
-
IllegalArgumentException- ifidis not in the rangeINPUT_METHOD_FIRST..INPUT_METHOD_LAST; or if id isCARET_POSITION_CHANGEDandtextis notnull; or ifcommittedCharacterCountis not in the range0..(text.getEndIndex() - text.getBeginIndex()) -
IllegalArgumentException- ifsourceis null
InputMethodEvent
public InputMethodEvent(Component source, int id, TextHitInfo caret, TextHitInfo visiblePosition)
InputMethodEvent with the specified source component, type, caret, and visiblePosition. The text is set to null, committedCharacterCount to 0. The offsets of caret and visiblePosition are relative to the current composed text; that is, the composed text within the text of the preceding INPUT_METHOD_TEXT_CHANGED event if the event being constructed as a CARET_POSITION_CHANGED event. For an INPUT_METHOD_TEXT_CHANGED event without text, caret and visiblePosition must be null. The time stamp for this event is initialized by invoking EventQueue.getMostRecentEventTime().
Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.
- Parameters:
-
source- the object where the event originated -
id- the event type -
caret- the caret (a.k.a. insertion point);nullif there's no caret within current composed text -
visiblePosition- the position that's most important to be visible;nullif there's no recommendation for a visible position within current composed text - Throws:
-
IllegalArgumentException- ifidis not in the rangeINPUT_METHOD_FIRST..INPUT_METHOD_LAST -
IllegalArgumentException- ifsourceis null
Method Details
getText
public AttributedCharacterIterator getText()
getCommittedCharacterCount() - 1 are committed text, the remaining characters are composed text.- Returns:
- the text. Always null for CARET_POSITION_CHANGED; may be null for INPUT_METHOD_TEXT_CHANGED if there's no composed or committed text.
getCommittedCharacterCount
public int getCommittedCharacterCount()
- Returns:
- the number of committed characters in the text
getCaret
public TextHitInfo getCaret()
The offset of the caret is relative to the current composed text; that is, the composed text within getText() if this is an INPUT_METHOD_TEXT_CHANGED event, the composed text within getText() of the preceding INPUT_METHOD_TEXT_CHANGED event otherwise.
- Returns:
- the caret (a.k.a. insertion point). Null if there's no caret within current composed text.
getVisiblePosition
public TextHitInfo getVisiblePosition()
The offset of the visible position is relative to the current composed text; that is, the composed text within getText() if this is an INPUT_METHOD_TEXT_CHANGED event, the composed text within getText() of the preceding INPUT_METHOD_TEXT_CHANGED event otherwise.
- Returns:
- the position that's most important to be visible. Null if there's no recommendation for a visible position within current composed text.
consume
isConsumed
public boolean isConsumed()
- Overrides:
-
isConsumedin classAWTEvent - Returns:
-
trueif this event has been consumed; otherwisefalse - See Also:
getWhen
public long getWhen()
- Returns:
- this event's timestamp
- Since:
- 1.4
paramString
public String paramString()
- Overrides:
-
paramStringin classAWTEvent - Returns:
- a string identifying the event and its attributes
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.