如何在JPanel中获取textarea的位置 [英] How to get location of textarea in JPanel

查看:308
本文介绍了如何在JPanel中获取textarea的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含2个JPanels(panel1,panel2) JFrame .我在panel1中添加了panel2. panel1.add(panel2);

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

我已在panel2中添加了一个文本区域.

i have added a text area into panel2.

panel2.add(textarea);

最终将panel1更改为getContentPane

finally panel1 to getContentPane

getContentPane().add(panel1);

现在我要通过以下方式获取textarea的位置

now i am getting the location of textarea by

textarea.getLocation();

textarea.getLocation();

我创建了一个Save按钮,用于保存textarea(x,y)值.我正在使用xml来存储(x,y)值.

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

现在,当我关闭并重新打开jar文件时,textarea的位置没有改变,但是xml值显示了更改后的textarea的位置值.

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 .

如何解决?

预先感谢

推荐答案

尝试使用textarea.getLocation()textarea.getLocationOnScreen()以获得左上角,然后使用getSize()计算文本区域的扩展范围.

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

这篇关于如何在JPanel中获取textarea的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆