[英]Access JTextArea text of Parent JDialog from another JDialog
I have two JDialog
. 我有两个
JDialog
。 First one is main one named MainJDialog
. 第一个是主要的
MainJDialog
。 Second one is child one named ChildJDialog
. 第二个是一个名为
ChildJDialog
孩子。 And i have JButton
in MainJDialog
which get ChildJDialog
to screen when pressed like this; 而且我在
MainJDialog
中有一个JButton
,当按下这样的MainJDialog
,它ChildJDialog
在屏幕上;
ChildJDialog childJDialog;
childJDialog = new ChildJDialog (MainJDialog.this, true);
childJDialog.setVisible(true);
Also i have several JTextArea
in MainJDialog
filled with user entered informations. 我在
MainJDialog
也有几个JTextArea
, MainJDialog
填充了用户输入的信息。
I have added JButton
to ChildJDialog
and want access of spesific JTextArea
text of currently running owner MainJDialog
when pressed. 我已将
JButton
添加到ChildJDialog
并希望在按下时访问当前运行的所有者MainJDialog
JTextArea
文本。
private void getTextOfJTextArea1ButtonActionPerformed(java.awt.event.ActionEvent evt)
{
System.out.println(ChildJDialog.this.getOwner().getClass());
}
Result: 结果:
class tryingproject.MainJDialog
Above ActionEvent
gives me true owner JDialog
but i dont know how can access its components. 上面的
ActionEvent
给了我真正的所有者JDialog
但我不知道如何访问其组件。
Any helps appreciated. 任何帮助表示赞赏。 Thanks.
谢谢。
--- SOLVED --- - - 解决了 - -
I create a constructor in ChildJDialog
and pass the JTextArea1 text of MainJDialog
as parameter to the ChildJDialog
when user call the ChildJDialog
just like below; 我创建一个构造函数
ChildJDialog
和传递的JTextArea1文本MainJDialog
作为参数传递给ChildJDialog
当用户调用ChildJDialog
就像下面;
ChildJDialog childJDialog;
childJDialog = new ChildJDialog (MainJDialog.this, true, textOfJTextArea1);
childJDialog.setVisible(true);
And i use this text anywhere in ChildJDialog
我在
ChildJDialog
任何地方使用此文本
Not the exact solution i know but working for now. 我不知道确切的解决方案,但现在可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.