So, I have a program that allows me to dynamically add JTextAreas and then drag them around the screen. The problem is, when I add a new JTextArea, I call revlidate() to update the panel. This causes all of the JTextAreas to reset their positions. How can I prevent this from happening? It is happening on this code:
I'm not sure what you mean "random". I will be allowing the user to drag the boxes around.
Your link helps a lot, but I'm still fuzzy on how a LayoutManager does this. Where exactly in the DragLayout is it fixing the revalidate() problem that I am having?
posted 4 years ago
Normally a layout manager sets the size/location of a component (among other things). The DragLayout doesn't set the location. It respects that the component can be dragged around the panel, so it just sets the size of the component. So when you invoke revalidate(), the layout manager is called and the size of the component is set (if required) but the location is not changed.
Read the Swing tutorial on Layout Managers for more information about how layout managers work.