# Finding nested Java components

**URL:** <https://forum.inductiveautomation.com/t/finding-nested-java-components/9946>\
**Category:** General Discussion\
**Created:** [April 22, 2015, 6:03pm UTC](https://forum.inductiveautomation.com/t/finding-nested-java-components/9946 "2015-04-22T18:03:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [April 22, 2015, 6:03pm UTC](https://forum.inductiveautomation.com/t/finding-nested-java-components/9946/1 "2015-04-22T18:03:48Z")

</div>

I figured out how to change the caret color for the underlying JTextArea of a PMITextArea but it seems like there is probably a better or cleaner way to do this.

What is a better way to do this?

`
text_area = event.source.getComponent("Text Area Whatever")
children = text_area .getComponents()
for child in children:
	if type(child). __name__ == "JViewport":
		vpChildren = child.getComponents()
		for vpChild in vpChildren:
			if type(vpChild). __name__ == "JTextArea":
				vpChild.setCaretColor(java.awt.Color.green)`

---

<div class="post-metadata">

**Author:** ![dave.fogle](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dave.fogle](https://forum.inductiveautomation.com/u/dave.fogle)\
**Post date:** [April 22, 2015, 9:30pm UTC](https://forum.inductiveautomation.com/t/finding-nested-java-components/9946/2 "2015-04-22T21:30:46Z")

</div>

You don't need to loop through everything. You can just do the following:

```python
from java.awt import Color
area = event.source.parent.getComponent("Text Area")
area.viewport.view.setCaretColor(Color.green)
```

Hope this helps.  
Also, in the future this sort of post might be better fit for the Ignition Design Help area.

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [April 22, 2015, 10:08pm UTC](https://forum.inductiveautomation.com/t/finding-nested-java-components/9946/3 "2015-04-22T22:08:08Z")

</div>

[quote=“dave.fogle”]You don’t need to loop through everything. You can just do the following:

```auto
from java.awt import Color
area = event.source.parent.getComponent("Text Area")
area.viewport.view.setCaretColor(Color.green)
```

Hope this helps.  
Also, in the future this sort of post might be better fit for the Ignition Design Help area.[/quote]

Thanks! That’s exactly what I was looking for.
