This is a JBR API for text-input related functionality for applications that implement custom text components.
Suppose an application implements a custom text component called CustomTextComponent
, that
doesn't inherit from TextComponent
or JTextComponent
.
For this component to work correctly, the application needs to handle certain events that are missing from
the Java specification.
To do this, the application should add an event listener for the events provided by this API.
This is best done at application startup time, since the event listener is global, and not per-component.
For example, this would be a proper way to implement this event handler for CustomTextComponent
:
var textInput = JBR.getTextInput();
if (textInput != null) {
textInput.setGlobalEventListener(new TextInput.EventListener() {
@Override
public void handleSelectTextRangeEvent(TextInput.SelectTextRangeEvent event) {
if (event.getSource() instanceof CustomTextComponent) {
((CustomTextComponent)event.getSource()).select(event.getBegin(), event.getBegin() + event.getLength());
}
}
});
}
This assumes that CustomTextComponent
has a method called select
, that selects a text range,
similar to the TextComponent.select(int, int)
and JTextComponent.select(int, int)
.
See TextInput.SelectTextRangeEvent
for more information.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Event listener interface for all events supported by this API.static interface
Custom text components that do not extendTextComponent
orJTextComponent
should subscribe to this event. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Sets the global event listener for text input/IME related events.
-
Method Details
-
setGlobalEventListener
Sets the global event listener for text input/IME related events. This should ideally be called once on the application startup. Passing null will remove the listener. The listener will only be called on the event dispatch thread (EDT).- Parameters:
listener
- listener
-