Q: JComboBox is not refreshing after the addition of new data in file I'm working on a project in java. I am facing a problem in refreshing the combo box after adding new data in file. Combo box is in one file(class / frame) and add form is in another file / class.
SetPackages.java (this class is adding new data):
Packages pkg = new Packages(Integer.parseInt(TPkgId.getText()), TPkgName.getText(), Integer.parseInt(String.valueOf(CBminGuest.getSelectedItem())), Integer.parseInt(String.valueOf(CBmaxGuest.getSelectedItem())), Integer.parseInt(TMeal.getText()), Integer.parseInt(TMusic.getText()), Integer.parseInt(TDecoration.getText()));
ObjectOutputStream outputStream = null;
try {
    ArrayList<Packages> PackageList = readAllData();
    PackageList.add(pkg);
    outputStream = new ObjectOutputStream(new FileOutputStream("packages.ser"));
    for(int i = 0 ; i < PackageList.size() ; i++) {
        outputStream.writeObject(PackageList.get(i));                                                                                                                                                                                                                                
    }
    outputStream.close();                   
    JOptionPane.showMessageDialog(new JFrame(), "New Package Added Successfully");     
    ClearForm();
    Events ev = new Events(); //here I'm creating object to call method of 2nd class to populate combo box again
    ev.createComboBox();
}catch(IOException e) {
    System.out.println("IO Exception while opening file");
} finally { 
    try {
        if(outputStream != null) {
           outputStream.close();                                
        }
    } catch (IOException e) {
        System.out.println("IO Exception while closing file");
    }
}

Events.java (here is the combo box):
public class Events extends JInternalFrame {
JTabbedPane tabs;
JPanel panel1;
JPanel panel2;
SpringLayout layout;
JLabel p1Head, PkgCode;
JComboBox CBPkgCode;

public Events(){
    super("Manage Events", false, true, false, false);
    tabs = new JTabbedPane();
    layout = new SpringLayout();
    ButtonHolder b = new ButtonHolder();

    panel1 = new JPanel(); 
    panel1.setLayout(layout);
    p1Head = new JLabel("Book An Event"); 
    p1Head.setFont(new Font("Arial Rounded MT Bold", 4, 18));
    PkgCode = new JLabel("Package Code");
    PkgCode.setFont(new Font("Arial Rounded MT Bold", 4, 14));
    CBPkgCode = new JComboBox();
    createComboBox();
    panel1.add(p1Head);
    panel1.add(PkgCode);
    panel1.add(CBPkgCode);
    layout.putConstraint(SpringLayout.WEST, p1Head, 300, SpringLayout.WEST, this);
    layout.putConstraint(SpringLayout.NORTH, p1Head, 20, SpringLayout.NORTH, this);
    layout.putConstraint(SpringLayout.WEST, PkgCode, 50, SpringLayout.WEST, this);
    layout.putConstraint(SpringLayout.NORTH, PkgCode, 40, SpringLayout.NORTH, p1Head);
    layout.putConstraint(SpringLayout.WEST, CBPkgCode, 150, SpringLayout.WEST, PkgCode);
    layout.putConstraint(SpringLayout.NORTH, CBPkgCode, 40, SpringLayout.NORTH, p1Head);
    tabs.addTab("Book an Event", panel1);

    add(tabs);
}

public void createComboBox(){
    List<String> codes = new ArrayList<String>();
    ObjectInputStream inputStream = null;
    try{
        inputStream = new ObjectInputStream(new FileInputStream("packages.ser"));
        boolean EOF = false;
        while(!EOF) {
            try {
                Packages myObj = (Packages) inputStream.readObject();
                codes.add(String.valueOf(myObj.getPkg_id()));
            }     
            catch (ClassNotFoundException e) {
            } catch (EOFException end) {
                EOF = true;
            }
        }
    } catch(FileNotFoundException e) {
        System.out.println("Cannot find file");
    } catch (IOException e) {
        System.out.println("IO Exception while opening stream");
    } finally { // cleanup code to close stream if it was opened
         try {
            if(inputStream != null)
                inputStream.close( );
         } catch (IOException e) {
            System.out.println("IO Exception while closing file");
         }
    }
    String[] codesArray = codes.toArray(new String[]{});
    CBPkgCode.setModel(new javax.swing.DefaultComboBoxModel(codesArray));
  }       
}

I'm calling createComboBox() method in SetPackages.java but it is not refreshing the combo box. Kindly help me out.

A: 
  Events ev = new Events(); //here I'm creating object to call method of 2nd class to populate combo box again


Here you create a new object with a new JComboBox CBPkgCode but you never add that to the current GUI.
