Using components in Client (Building HMIs in Client)

I would like to build HMIs in client (just you can in designer). So I will be using components like button, label, lines and so on in client.
For a start I wanted to add a button on Root Container with actionPerformed script:

root=event.source.parent

from com.inductiveautomation.factorypmi.application.components import PMIButton
from javax.swing import *

button= PMIButton()
root.add(button)

But I get an error saying that you can’t add directly to a container.
I successfully added button to another component (Template Canvas), but I can’t move it or do anything with it.
If someone can help me and point me to the right direction how to achieve that.

The supported way to create such dynamic user interfaces is to populate a template canvas with template instances with explicit locations and sizes.
Ignition windows are complex beasts with lots of interlocking requirements beyond what you might know about Swing. You are blazing an unsupported trail that I think will end in tears. Spend some time building Java components in modules for use in Ignition to get a feel for the complexity.