InputMethodEvent (Java Platform SE 8 ) (original) (raw)
- java.util.EventObject
- java.awt.AWTEvent
- java.awt.event.InputMethodEvent
- java.awt.AWTEvent
All Implemented Interfaces:
Serializable
public class InputMethodEvent
extends AWTEvent
Input method events contain information about text that is being composed using an input method. Whenever the text changes, the input method sends an event. If the text component that's currently using the input method is an active client, the event is dispatched to that component. Otherwise, it is dispatched to a separate composition window.
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:
Serialized Form
Field Summary
Fields
Modifier and Type Field Description static int CARET_POSITION_CHANGED The event type indicating a changed insertion point in input method text. static int INPUT_METHOD_FIRST Marks the first integer id for the range of input method event ids. static int INPUT_METHOD_LAST Marks the last integer id for the range of input method event ids. static int INPUT_METHOD_TEXT_CHANGED The event type indicating changed input method text. * ### Fields inherited from class java.awt.[AWTEvent](../../../java/awt/AWTEvent.html "class in java.awt") `[ACTION_EVENT_MASK](../../../java/awt/AWTEvent.html#ACTION%5FEVENT%5FMASK), [ADJUSTMENT_EVENT_MASK](../../../java/awt/AWTEvent.html#ADJUSTMENT%5FEVENT%5FMASK), [COMPONENT_EVENT_MASK](../../../java/awt/AWTEvent.html#COMPONENT%5FEVENT%5FMASK), [consumed](../../../java/awt/AWTEvent.html#consumed), [CONTAINER_EVENT_MASK](../../../java/awt/AWTEvent.html#CONTAINER%5FEVENT%5FMASK), [FOCUS_EVENT_MASK](../../../java/awt/AWTEvent.html#FOCUS%5FEVENT%5FMASK), [HIERARCHY_BOUNDS_EVENT_MASK](../../../java/awt/AWTEvent.html#HIERARCHY%5FBOUNDS%5FEVENT%5FMASK), [HIERARCHY_EVENT_MASK](../../../java/awt/AWTEvent.html#HIERARCHY%5FEVENT%5FMASK), [id](../../../java/awt/AWTEvent.html#id), [INPUT_METHOD_EVENT_MASK](../../../java/awt/AWTEvent.html#INPUT%5FMETHOD%5FEVENT%5FMASK), [INVOCATION_EVENT_MASK](../../../java/awt/AWTEvent.html#INVOCATION%5FEVENT%5FMASK), [ITEM_EVENT_MASK](../../../java/awt/AWTEvent.html#ITEM%5FEVENT%5FMASK), [KEY_EVENT_MASK](../../../java/awt/AWTEvent.html#KEY%5FEVENT%5FMASK), [MOUSE_EVENT_MASK](../../../java/awt/AWTEvent.html#MOUSE%5FEVENT%5FMASK), [MOUSE_MOTION_EVENT_MASK](../../../java/awt/AWTEvent.html#MOUSE%5FMOTION%5FEVENT%5FMASK), [MOUSE_WHEEL_EVENT_MASK](../../../java/awt/AWTEvent.html#MOUSE%5FWHEEL%5FEVENT%5FMASK), [PAINT_EVENT_MASK](../../../java/awt/AWTEvent.html#PAINT%5FEVENT%5FMASK), [RESERVED_ID_MAX](../../../java/awt/AWTEvent.html#RESERVED%5FID%5FMAX), [TEXT_EVENT_MASK](../../../java/awt/AWTEvent.html#TEXT%5FEVENT%5FMASK), [WINDOW_EVENT_MASK](../../../java/awt/AWTEvent.html#WINDOW%5FEVENT%5FMASK), [WINDOW_FOCUS_EVENT_MASK](../../../java/awt/AWTEvent.html#WINDOW%5FFOCUS%5FEVENT%5FMASK), [WINDOW_STATE_EVENT_MASK](../../../java/awt/AWTEvent.html#WINDOW%5FSTATE%5FEVENT%5FMASK)` * ### Fields inherited from class java.util.[EventObject](../../../java/util/EventObject.html "class in java.util") `[source](../../../java/util/EventObject.html#source)`
Constructor Summary
Constructors
Constructor Description InputMethodEvent(Component source, int id,AttributedCharacterIterator text, int committedCharacterCount,TextHitInfo caret,TextHitInfo visiblePosition) Constructs an InputMethodEvent with the specified source component, type, text, caret, and visiblePosition. InputMethodEvent(Component source, int id, long when,AttributedCharacterIterator text, int committedCharacterCount,TextHitInfo caret,TextHitInfo visiblePosition) Constructs an InputMethodEvent with the specified source component, type, time, text, caret, and visiblePosition. InputMethodEvent(Component source, int id,TextHitInfo caret,TextHitInfo visiblePosition) Constructs an InputMethodEvent with the specified source component, type, caret, and visiblePosition. Method Summary
All Methods Instance Methods Concrete Methods
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 inherited from class java.awt.[AWTEvent](../../../java/awt/AWTEvent.html "class in java.awt") `[getID](../../../java/awt/AWTEvent.html#getID--), [setSource](../../../java/awt/AWTEvent.html#setSource-java.lang.Object-), [toString](../../../java/awt/AWTEvent.html#toString--)` * ### Methods inherited from class java.util.[EventObject](../../../java/util/EventObject.html "class in java.util") `[getSource](../../../java/util/EventObject.html#getSource--)` * ### Methods inherited from class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[clone](../../../java/lang/Object.html#clone--), [equals](../../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../../java/lang/Object.html#finalize--), [getClass](../../../java/lang/Object.html#getClass--), [hashCode](../../../java/lang/Object.html#hashCode--), [notify](../../../java/lang/Object.html#notify--), [notifyAll](../../../java/lang/Object.html#notifyAll--), [wait](../../../java/lang/Object.html#wait--), [wait](../../../java/lang/Object.html#wait-long-), [wait](../../../java/lang/Object.html#wait-long-int-)`
Field Detail
* #### INPUT\_METHOD\_FIRST [@Native](../../../java/lang/annotation/Native.html "annotation in java.lang.annotation") public static final int INPUT_METHOD_FIRST Marks the first integer id for the range of input method event ids. See Also: [Constant Field Values](../../../constant-values.html#java.awt.event.InputMethodEvent.INPUT%5FMETHOD%5FFIRST) * #### INPUT\_METHOD\_TEXT\_CHANGED [@Native](../../../java/lang/annotation/Native.html "annotation in java.lang.annotation") public static final int INPUT_METHOD_TEXT_CHANGED The event type indicating changed input method text. This event is generated by input methods while processing input. See Also: [Constant Field Values](../../../constant-values.html#java.awt.event.InputMethodEvent.INPUT%5FMETHOD%5FTEXT%5FCHANGED) * #### CARET\_POSITION\_CHANGED [@Native](../../../java/lang/annotation/Native.html "annotation in java.lang.annotation") public static final int CARET_POSITION_CHANGED The event type indicating a changed insertion point in input method text. This event is generated by input methods while processing input if only the caret changed. See Also: [Constant Field Values](../../../constant-values.html#java.awt.event.InputMethodEvent.CARET%5FPOSITION%5FCHANGED) * #### INPUT\_METHOD\_LAST [@Native](../../../java/lang/annotation/Native.html "annotation in java.lang.annotation") public static final int INPUT_METHOD_LAST Marks the last integer id for the range of input method event ids. See Also: [Constant Field Values](../../../constant-values.html#java.awt.event.InputMethodEvent.INPUT%5FMETHOD%5FLAST)
Constructor Detail
* #### InputMethodEvent public InputMethodEvent([Component](../../../java/awt/Component.html "class in java.awt") source, int id, long when, [AttributedCharacterIterator](../../../java/text/AttributedCharacterIterator.html "interface in java.text") text, int committedCharacterCount, [TextHitInfo](../../../java/awt/font/TextHitInfo.html "class in java.awt.font") caret, [TextHitInfo](../../../java/awt/font/TextHitInfo.html "class in java.awt.font") visiblePosition) Constructs an `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 be `null` when the event type is `CARET_POSITION_CHANGED`; may be `null` for`INPUT_METHOD_TEXT_CHANGED` if there's no committed or composed text `committedCharacterCount` \- the number of committed characters in the text `caret` \- the caret (a.k.a. insertion point);`null` if there's no caret within current composed text `visiblePosition` \- the position that's most important to be visible; `null` if there's no recommendation for a visible position within current composed text Throws: `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `id` is not in the range`INPUT_METHOD_FIRST`..`INPUT_METHOD_LAST`; or if id is `CARET_POSITION_CHANGED` and`text` is not `null`; or if `committedCharacterCount` is not in the range`0`..`(text.getEndIndex() - text.getBeginIndex())` `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `source` is null Since: 1.4 * #### InputMethodEvent public InputMethodEvent([Component](../../../java/awt/Component.html "class in java.awt") source, int id, [AttributedCharacterIterator](../../../java/text/AttributedCharacterIterator.html "interface in java.text") text, int committedCharacterCount, [TextHitInfo](../../../java/awt/font/TextHitInfo.html "class in java.awt.font") caret, [TextHitInfo](../../../java/awt/font/TextHitInfo.html "class in java.awt.font") visiblePosition) Constructs an `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()](../../../java/awt/EventQueue.html#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 be `null` when the event type is `CARET_POSITION_CHANGED`; may be `null` for`INPUT_METHOD_TEXT_CHANGED` if there's no committed or composed text `committedCharacterCount` \- the number of committed characters in the text `caret` \- the caret (a.k.a. insertion point);`null` if there's no caret within current composed text `visiblePosition` \- the position that's most important to be visible; `null` if there's no recommendation for a visible position within current composed text Throws: `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `id` is not in the range`INPUT_METHOD_FIRST`..`INPUT_METHOD_LAST`; or if id is `CARET_POSITION_CHANGED` and`text` is not `null`; or if `committedCharacterCount` is not in the range`0`..`(text.getEndIndex() - text.getBeginIndex())` `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `source` is null * #### InputMethodEvent public InputMethodEvent([Component](../../../java/awt/Component.html "class in java.awt") source, int id, [TextHitInfo](../../../java/awt/font/TextHitInfo.html "class in java.awt.font") caret, [TextHitInfo](../../../java/awt/font/TextHitInfo.html "class in java.awt.font") visiblePosition) Constructs an `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()](../../../java/awt/EventQueue.html#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);`null` if there's no caret within current composed text `visiblePosition` \- the position that's most important to be visible; `null` if there's no recommendation for a visible position within current composed text Throws: `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `id` is not in the range`INPUT_METHOD_FIRST`..`INPUT_METHOD_LAST` `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `source` is null
Method Detail
* #### getText public [AttributedCharacterIterator](../../../java/text/AttributedCharacterIterator.html "interface in java.text") getText() Gets the combined committed and composed text. Characters from index 0 to index `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() Gets the number of committed characters in the text. * #### getCaret public [TextHitInfo](../../../java/awt/font/TextHitInfo.html "class in java.awt.font") getCaret() Gets the caret. 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](../../../java/awt/font/TextHitInfo.html "class in java.awt.font") getVisiblePosition() Gets the position that's most important to be visible. 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 public void consume() Consumes this event so that it will not be processed in the default manner by the source which originated it. Overrides: `[consume](../../../java/awt/AWTEvent.html#consume--)` in class `[AWTEvent](../../../java/awt/AWTEvent.html "class in java.awt")` * #### isConsumed public boolean isConsumed() Returns whether or not this event has been consumed. Overrides: `[isConsumed](../../../java/awt/AWTEvent.html#isConsumed--)` in class `[AWTEvent](../../../java/awt/AWTEvent.html "class in java.awt")` See Also: [consume()](../../../java/awt/event/InputMethodEvent.html#consume--) * #### getWhen public long getWhen() Returns the time stamp of when this event occurred. Returns: this event's timestamp Since: 1.4 * #### paramString public [String](../../../java/lang/String.html "class in java.lang") paramString() Returns a parameter string identifying this event. This method is useful for event-logging and for debugging. It contains the event ID in text form, the characters of the committed and composed text separated by "+", the number of committed characters, the caret, and the visible position. Overrides: `[paramString](../../../java/awt/AWTEvent.html#paramString--)` in class `[AWTEvent](../../../java/awt/AWTEvent.html "class in java.awt")` Returns: a string identifying the event and its attributes
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, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.