Z order in runtime

Hi

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

Br
Tommi

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”:

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)

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

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.

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??

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:

cont.repaint()
1 Like

does this work in perspective?