Package com.jetbrains

Interface TextInput


@Service @Provided public interface TextInput
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.
  • Method Details

    • setGlobalEventListener

      void setGlobalEventListener(TextInput.EventListener listener)
      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