Page 1 of 1

AddChildComponent() - how does it work?

Posted: Sun Feb 21, 2021 7:23 pm
by Captain
When I try to use AddChildComponent() for any GUI element, the child component simply disappears? For example, I have two text labels, and do this in the code:

Code: Select all

textLabel1.AddChildComponent( textLabel2 );
As soon as I do that, textLabel2 disappears from the interface. I have tried moving both components, setting their visibility to true, etc, but textLabel2 stays awol. Is there something super obvious I'm missing? The only documentation I found is the short javadoc description...

Re: AddChildComponent() - how does it work?

Posted: Sun Feb 21, 2021 8:19 pm
by rsover
I think the parent component should be a container component. https://docs.oracle.com/javase/tutorial ... index.html

I have not done VMDesiner development so far, but could be a solution.

Re: AddChildComponent() - how does it work?

Posted: Mon Feb 22, 2021 2:20 am
by Cherry Garcia
Set the position relative to the parent. That should help.

Re: AddChildComponent() - how does it work?

Posted: Mon Feb 22, 2021 7:38 am
by Captain
Cherry Garcia wrote: Mon Feb 22, 2021 2:20 am Set the position relative to the parent. That should help.
Yes, now I got it, thank you! But it also seems that the child component needs to be inside the parent's bounding rectangle, the rest is cut off. No problem, I just thought that the parent-child-relationship would simply mean locking the components' coordinates to each other, no matter what their initial placement is (like the "Link selected controls" option), that's what threw me off. :)
rsover wrote: Sun Feb 21, 2021 8:19 pm I think the parent component should be a container component. https://docs.oracle.com/javase/tutorial ... index.html
Yeah, indeed it looks like the parent component is treated like a container. What confused is me that you can add children to all GUI elements (text labels, buttons, etc), which don't "feel" like containers the same way a canvas does, for example. :D

Re: AddChildComponent() - how does it work?

Posted: Mon Feb 22, 2021 8:01 pm
by Cherry Garcia
(= Glad you got it figured out. The upcoming Piano Roll module uses child components extensively. Each note object is a VoltageRectangle inside of VoltageViewport. Hovering over a note object will add a label over the note object in order to show it's note value, for example. Should be coming up in the next month or so.