# Why can't custom properties and methods be accessed from a component that is obtained using SwingUtilities.getAncestorOfClass?

**URL:** <https://forum.inductiveautomation.com/t/why-cant-custom-properties-and-methods-be-accessed-from-a-component-that-is-obtained-using-swingutilities-getancestorofclass/78606>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [August 31, 2023, 10:07am UTC](https://forum.inductiveautomation.com/t/why-cant-custom-properties-and-methods-be-accessed-from-a-component-that-is-obtained-using-swingutilities-getancestorofclass/78606 "2023-08-31T10:07:05Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 1, 2023, 12:20am UTC](https://forum.inductiveautomation.com/t/why-cant-custom-properties-and-methods-be-accessed-from-a-component-that-is-obtained-using-swingutilities-getancestorofclass/78606/3 "2023-09-01T00:20:03Z")

</div>

> [@pturmel](#):
>
> Custom properties are added to the java standard jython conversion by IA's `PyComponentWrapper`.

Thanks for the hint. Wrapping the swing utility call in the PyComponentWrapper returns the object with the custom properties accessible.

Just for completeness and clarity; the recursive approach always works for returning a component with its custom properties.

**Recursive example to get the parent container of a component:**

```auto
from com.inductiveautomation.factorypmi.application.components import BasicContainer
def getParentContainer(component):
	if isinstance(component.parent, BasicContainer):
		return component.parent
	else:
		parentContainer = getParentContainer(component.parent)
		if parentContainer is not None:
			return parentContainer
parentContainer = getParentContainer(event.source)

```

The getAncestorOfClass approach returns the expected component and takes far fewer lines of code, but all custom properties are lost:

**Basic SwingUtilities Example:**

```auto
from com.inductiveautomation.factorypmi.application.components import BasicContainer
from javax.swing import SwingUtilities
parentContainer = SwingUtilities.getAncestorOfClass(BasicContainer, event.source)

```

By simply wrapping the swing utility call in a pyComponentWrapper call, the component is returned with the custom properties just like the recursive approach.

**pyComponentWrapper with SwingUtilities example:**

```auto
from com.inductiveautomation.factorypmi.application.components import BasicContainer
from com.inductiveautomation.factorypmi.application.script import PyComponentWrapper
from javax.swing import SwingUtilities
parentContainer = PyComponentWrapper(SwingUtilities.getAncestorOfClass(BasicContainer, event.source))

```

It's only one more line of code, and it's still cleaner looking than building a recursive function.

---

_[View the full topic](https://forum.inductiveautomation.com/t/why-cant-custom-properties-and-methods-be-accessed-from-a-component-that-is-obtained-using-swingutilities-getancestorofclass/78606)._
