# Z order in runtime

**URL:** <https://forum.inductiveautomation.com/t/z-order-in-runtime/4934>\
**Category:** Ignition\
**Created:** [August 6, 2012, 5:04pm UTC](https://forum.inductiveautomation.com/t/z-order-in-runtime/4934 "2012-08-06T17:04:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vahterto](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vahterto](https://forum.inductiveautomation.com/u/vahterto)\
**Post date:** [August 6, 2012, 5:04pm UTC](https://forum.inductiveautomation.com/t/z-order-in-runtime/4934/1 "2012-08-06T17:04:44Z")

</div>

Hi

Is it possible to change graphics components z order in runtime?  
Like X and Y.

Br  
Tommi

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [August 6, 2012, 5:21pm UTC](https://forum.inductiveautomation.com/t/z-order-in-runtime/4934/2 "2012-08-06T17:21:02Z")

</div>

Yes, it is possible. The root container of a window is a Java Container, so it can use setComponentZOrder(). Here is an example of a script which changes the z order of components on a window called “Main Window”:

```auto
cont = system.gui.getWindow('Main Window').getRootContainer()

comp = cont.getComponent("Multi-State Indicator")
comp1 = cont.getComponent("Moving Analog Indicator")
comp2 = cont.getComponent("LED Display")

cont.setComponentZOrder(comp,0)
cont.setComponentZOrder(comp1,1)
cont.setComponentZOrder(comp2,2)
```

---

<div class="post-metadata">

**Author:** ![vahterto](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vahterto](https://forum.inductiveautomation.com/u/vahterto)\
**Post date:** [August 6, 2012, 6:12pm UTC](https://forum.inductiveautomation.com/t/z-order-in-runtime/4934/3 "2012-08-06T18:12:41Z")

</div>

Thanks !  
I was sure that there is solution to do this .

BTW: If I just want to change component which is top of others; Do I have to change all components z order?

Br  
Tommi

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [August 6, 2012, 6:22pm UTC](https://forum.inductiveautomation.com/t/z-order-in-runtime/4934/4 "2012-08-06T18:22:40Z")

</div>

Yes, you would have to change the z order of every component. Changing the order of one component will change at least the order of one other component, since no two components can be on the same “level”. So if you put a component on top (i.e., level “0”), that component on top can no longer be at level 0, it must be changed to a different level.

---

<div class="post-metadata">

**Author:** ![vahterto](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vahterto](https://forum.inductiveautomation.com/u/vahterto)\
**Post date:** [August 7, 2012, 7:16am UTC](https://forum.inductiveautomation.com/t/z-order-in-runtime/4934/5 "2012-08-07T07:16:45Z")

</div>

Hi

Some reason this script does not seems to be working in “runtime”.

cont = system.gui.getWindow(‘Left’).getRootContainer()

comp = cont.getComponent(“Rectangle”)  
comp1 = cont.getComponent(“Rectangle 1”)

cont.setComponentZOrder(comp,0)  
cont.setComponentZOrder(comp1,1)

It works only in designer and there also so that I have to toggle design/runtime mode between actions?  
Do I need some kind of refresh action??

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [August 7, 2012, 3:20pm UTC](https://forum.inductiveautomation.com/t/z-order-in-runtime/4934/6 "2012-08-07T15:20:11Z")

</div>

Yes, you would need to refresh the window, I forgot to add that in to the script. Calling a repaint() on the container where the components are located should do the trick. Add this to the end of your script:

```auto
cont.repaint()
```

---

<div class="post-metadata">

**Author:** ![kyle.demerath](https://avatars.discourse-cdn.com/v4/letter/k/5e9695/32.png) [@kyle.demerath](https://forum.inductiveautomation.com/u/kyle.demerath)\
**Post date:** [February 18, 2020, 7:13pm UTC](https://forum.inductiveautomation.com/t/z-order-in-runtime/4934/7 "2020-02-18T19:13:35Z")

</div>

does this work in perspective?
