Search code examples
javaswinglayoutjpaneljtextarea

How to place a text area in JPanel


I have created a JFrame containing 2 JPanels(panel1,panel2). I have added panel2 in panel1. panel1.add(panel2);

I have added a text area into panel2.

panel2.add(textarea);

finally panel1 to getContentPane

getContentPane().add(panel1);

Now I am getting the location of textarea by

textarea.getLocation();

I have created a Save button which saves the textarea(x,y) values. I am using xml to store (x,y) values.

Now when I close and reopen the jar file the textarea place is not changed but the xml values are showing the changed textarea location values .

How to solve?


Solution

  • do filing; put x and y values to some variables. Then put it on JTextArea textArea by ::

    textArea.setText(arg);