# Highlighting text

**URL:** <https://forum.inductiveautomation.com/t/highlighting-text/2165>\
**Category:** Ignition\
**Created:** [September 1, 2010, 12:30pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165 "2010-09-01T12:30:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 1, 2010, 12:30pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165/1 "2010-09-01T12:30:29Z")

</div>

I’m using a Formatted Text Field to restrict users input, before checking the value entered in code. If it is out of range, I warn the user and then reset focus to the control with`def resetFocus(textbox = event.source):
	textbox.requestFocusInWindow()
system.system.invokeLater(resetFocus)
`As well as resetting the focus I also want to highlight all the existing text in the text field. How do I do this?

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 1, 2010, 1:14pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165/2 "2010-09-01T13:14:08Z")

</div>

You could use html coding to do this. I have a window where I progromatically highlight certain words in the text, using something like this:

`
<FONT STYLE="BACKGROUND-COLOR: yellow">This is the highlighted text</font>`

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 1, 2010, 1:35pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165/3 "2010-09-01T13:35:33Z")

</div>

When I say highlight I mean the selection highlight (like when you click at the beginning of a word and drag you mouse over the rest of the word).

I want to highlight the existing content of the text field so that if the user types something the existing content is overwritten.

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 1, 2010, 1:50pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165/4 "2010-09-01T13:50:36Z")

</div>

Couldn’t you use the java clipboard and progromatically select it? In fact, you posted some code in the FPMI forum that could get you pretty close.

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 1, 2010, 1:52pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165/5 "2010-09-01T13:52:31Z")

</div>

I could if I could remember how! I’ve been looking for that post but couldn’t find it - do you have a reference?

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 1, 2010, 1:56pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165/6 "2010-09-01T13:56:45Z")

</div>

It shows up if you do a search on ‘clipboard’. It’s from March 2010.

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 1, 2010, 2:32pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165/7 "2010-09-01T14:32:38Z")

</div>

That post deals with reading already highlighted text using the getSelectedText() function. A quick Google seems to suggest that likely candidates for setting the selection text are setSelectionStart() and setSelectionEnd(), but they don’t seem to have any effect.

I have noticed that using requestFocusInWindow() with a standard Text Field automatically selects all the text in the field, but not with a Formatted Text Field.

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 1, 2010, 3:29pm UTC](https://forum.inductiveautomation.com/t/highlighting-text/2165/8 "2010-09-01T15:29:20Z")

</div>

I had to write to the clipboard on another system I was working on, and maybe there is something you could use in this post: [http://inductiveautomation.com/forum/viewtopic.php?f=23&t=4379&p=10176&hilit=clipboard#p10176](http://inductiveautomation.com/forum/viewtopic.php?f=23&t=4379&p=10176&hilit=clipboard#p10176)

I wonder if you could point the text property to the setContents parameter… No matter what, post your solution here. I think it could be useful. 🙂
