问题
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
回答1:
Try textarea.getLocation()
or textarea.getLocationOnScreen()
to get the top left corner, then use getSize()
to calculate how far the textarea extends.
来源:https://stackoverflow.com/questions/16685368/how-to-get-location-of-textarea-in-jpanel