Search code examples
javaswingjframepersistencejtextpane

Save location in flow layout


I have created a frame and two panels.

Jpanel pane11=new JPanel();
Jpanel pane12=new JPanel();

Added the panel2 to the panel1

panel1.add(panel2);
getContentPane().add(panel1);

Now I set the panel2 background white and it is working correctly

I have created 4 JTextPanes in the panel2 and made it draggable.

*Now what my problem is: If I drag a text pane from (0,0) to (10,10) and I save it the text pane has to reappear at (10,10) when I close and re open the frame. So how to get the location of jtextpanes in flowlayout *

I have created save button to save the changes in panel and I am using flow layout for panel2.

I am using XML file for saving the locations.


Solution

  • By design, FlowLayout will restore the panel to its calculated location when the enclosing Window is resized. As an alternative, consider JInternalFrame, which supports dragging in a JDesktopPane directly. Use the Preferences API to persist each internal frame's location.