How to get location of textarea in JPanel

半城伤御伤魂 提交于 2019-12-13 04:55:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!