What I'm trying to achive is basically the "Enclose in" feature of Netbeans at runtime:
Let's say I have this component hierarchy:
Container
Label 1
Label 2
Label 3
And I want to enclose Label 2
like this:
Container
Label 1
Container
Label 2
Label 3
And I also want to revert it, i.e. I want to "pull up" the label again to get the original hierarchy.
EDIT: The problem is that at runtime I only know Label 2
. Any other components (siblings, parents, children) are unknown. That eliminates the possibitlity to just reconstruct the hierarchy.
Of couse I'm sure I can find some way to get this functionality by traversing the component hierarchies, but I wonder:
Is there a better way? Perhaps some kind of utility class which provides this encapsulation feature?
EDIT 2: How do I get the layout constraints the component originally was added to the container? I need this information because the new container has to use the same constraints. Also when restoring the original hierarchy the component has to re-use its old constraints.