I have two JFrames jFrame1
and jFrame2
,in jFrame1 there's a textfield and a button,while clicking on button jFrame2 will appear. In jFrame2 there's also a textfield and a button.I will type a name in textfield of jFrame2 and by clicking the button in it that textfield value should appear on textfield of jFrame1. But I am not getting the focus transferred to jFrame1,i tried the code,
in jFrame1
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jFrame2 abc=new jFrame2();
abc.setVisible(true);
}
public void inserting(String name){
jTextField1.requestFocusInWindow();
jTextField1.setText(name);
}
in jFrame2,
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jFrame1 abc1=new jFrame1();
// abc1.transferFocus(); //not working
abc1.inserting(jTextField1.getText());
this.dispose();
}
I am getting value to the method inserting()
,but it's not getting set into the textfield. If I again give setVisible(true)
for jFrame1 it works,but I dont want to do i in that way. Is there any other way to resolve this?