简体   繁体   English

从另一个JDialog访问父JDialog的JTextArea文本

[英]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也有几个JTextAreaMainJDialog填充了用户输入的信息。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM