Prevent two components overlapping



How do/would you guys approach the task of keeping two components not able to touch eachother (stop the movement of the colliding direction, but still able to move the other 3 directions (sliding up and down the collision target)).. when moved/dragged?

The components will are childs of a container component, and they represents "physical objects"

Sorry for my poor explanation, but I hope somebody gets the point ;) 


There's certainly a number of ways it could be done but assuming the container is aware of all the "physical objects" you might want to make the container a mouse listener of the child components and enforce your constraints from there.