Be careful, this is a classic example of something where inexperienced coders always take the wrong approach!
The naive thing to do is to use something like a ComponentDragger or a mouseDrag callback which directly changes the component’s bounds. Yep, that’ll certainly move it around visually, which is fine if you don’t care where it ends up.
BUT if your app has any kind of state where the position of things is meaningful, or if actually use or save the positions, then you need to be smarter about it:
- Intercept the mouse drag events and make them tell your MODEL that the position of that object has changed. But do NOT make a mouse-drag move the component itself!
- Make sure that when you model changes, the appropriate components get their bounds updated.
The point of this is that you never use the position of a Component as part of your model’s state, you always update the GUI from the model and never make the GUI update itself in response to a user action.