Ananth
Ananth

Reputation: 51

How to get location of textarea 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??

Thanks in advance

Upvotes: 0

Views: 768

Answers (1)

Steven Morad
Steven Morad

Reputation: 2617

Try textarea.getLocation() or textarea.getLocationOnScreen() to get the top left corner, then use getSize() to calculate how far the textarea extends.

Upvotes: 2

Related Questions