# Getting editor from EditorTextField

**URL:** <https://platform.jetbrains.com/t/getting-editor-from-editortextfield/511>\
**Category:** IntelliJ Platform\
**Created:** [February 14, 2025, 7:12am UTC](https://platform.jetbrains.com/t/getting-editor-from-editortextfield/511 "2025-02-14T07:12:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![strindberg](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@strindberg](https://platform.jetbrains.com/u/strindberg)\
**Post date:** [February 14, 2025, 7:12am UTC](https://platform.jetbrains.com/t/getting-editor-from-editortextfield/511/1 "2025-02-14T07:12:50Z")

</div>

I have a textField (EditorTextField) where the user can input a search string. The textField is in turn part of a JPanel(GridBagLayout()), which is then used as the main component in a JBPopup.

I wanted to style a bit of the text in the field, and tried this:  
textField.editor?.markupModel?.addRangeHighlighter(…)

However, textField.editor returns null. Is there some kind of initialization that might be missing, or how does one make the editor be available?

---

<div class="post-metadata">

**Author:** ![picimako](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/picimako/32/171_2.png) [@picimako](https://platform.jetbrains.com/u/picimako)\
**Post date:** [February 14, 2025, 8:58pm UTC](https://platform.jetbrains.com/t/getting-editor-from-editortextfield/511/2 "2025-02-14T20:58:57Z")

</div>

You can do some formatting on the `EditorTextField` like font and background, and you can call `.addSettingsProvider()` on it too.

The lambda variable is of type `com.intellij.openapi.editor.ex.EditorEx`, so you have access to an Editor instance, and you can configure things like this: `textField.addSettingsProvider(provider -> provider.getSettings().setUseSoftWraps(true))`.

See if any of the settings options are suitable for what you need.

---

<div class="post-metadata">

**Author:** ![strindberg](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@strindberg](https://platform.jetbrains.com/u/strindberg)\
**Post date:** [February 15, 2025, 10:36am UTC](https://platform.jetbrains.com/t/getting-editor-from-editortextfield/511/3 "2025-02-15T10:36:17Z")

</div>

Thank you for the tips, but this is not exactly what I’m after. What I want to do is style a portion of the text in the field, i.e. make a part of it red (to signal an error in part of the string). That’s why I want to get hold of the editor and add a range highlighter. But the trouble is that `textField.editor` returns null.

---

<div class="post-metadata">

**Author:** ![picimako](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/picimako/32/171_2.png) [@picimako](https://platform.jetbrains.com/u/picimako)\
**Post date:** [February 17, 2025, 6:11pm UTC](https://platform.jetbrains.com/t/getting-editor-from-editortextfield/511/4 "2025-02-17T18:11:50Z")

</div>

I was curious, so I did a bit of digging, but the only potential alternative I found is this:

if `textField.document` returns a non-null value, calling `com.intellij.openapi.editor.EditorFactory.editors(textField.document)` might return the desired Editor instance too.

---

<div class="post-metadata">

**Author:** ![strindberg](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@strindberg](https://platform.jetbrains.com/u/strindberg)\
**Post date:** [February 17, 2025, 6:41pm UTC](https://platform.jetbrains.com/t/getting-editor-from-editortextfield/511/5 "2025-02-17T18:41:06Z")

</div>

Thank you, I appreciate the help. It doesn’t seem to work, however: `textField.document` is indeed non-null, but calling `EditorFactory.getInstance().editors(textField.document)` returns 0 editors, so no luck this way.
