It is currently Fri Jul 25, 2014 4:59 am




Post new topic Reply to topic  [ 6 posts ] 
 z order in runtime 
Author Message
Captain
Captain

Joined: Thu Apr 15, 2010 8:22 am
Posts: 99
Location: Tampere, Finland
Post z order in runtime
Hi

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

Br
Tommi


Mon Aug 06, 2012 9:04 am
Profile WWW
Moderator
Moderator

Joined: Mon Jun 04, 2012 8:53 am
Posts: 440
Post Re: z order in runtime
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":

Code:
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)

_________________
James Lorenz
QA/Build Systems Engineer
Inductive Automation


Mon Aug 06, 2012 9:21 am
Profile
Captain
Captain

Joined: Thu Apr 15, 2010 8:22 am
Posts: 99
Location: Tampere, Finland
Post Re: z order in runtime
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


Mon Aug 06, 2012 10:12 am
Profile WWW
Moderator
Moderator

Joined: Mon Jun 04, 2012 8:53 am
Posts: 440
Post Re: z order in runtime
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.

_________________
James Lorenz
QA/Build Systems Engineer
Inductive Automation


Mon Aug 06, 2012 10:22 am
Profile
Captain
Captain

Joined: Thu Apr 15, 2010 8:22 am
Posts: 99
Location: Tampere, Finland
Post Re: z order in runtime
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??


Mon Aug 06, 2012 11:16 pm
Profile WWW
Moderator
Moderator

Joined: Mon Jun 04, 2012 8:53 am
Posts: 440
Post Re: z order in runtime
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:

Code:
cont.repaint()

_________________
James Lorenz
QA/Build Systems Engineer
Inductive Automation


Tue Aug 07, 2012 7:20 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: