I have two jFrames: Frame1 and Frame2.
Frame1 has a jComboBox and a jButton; Frame2 has just a jButton.
Frame1 can open Frame2.
I have this code on Frame 1:
public class Frame1 extends javax.swing.JFrame {
public void addTextToComboBox(){
this.jComboBox1.removeAllItems();
this.jComboBox1.addItem("Hello");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.addTextToComboBox();
}
}
It works fine: The "Hello" string is added to the jComboBox when i click the jButton.
Now I have this code on Frame2:
public class Frame2 extends javax.swing.JFrame {
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Frame1 frame1=new Frame1();
frame1.addTextToComboBox();
}
}
This way, the "Hello" string is not added to the jComboBox on Frame1 when i click on the jButton on Frame2.
Why? Could someone get me a solution please?
Thanks in advance.