The idea is to load an array of objects onto a JComboBox. I have a Class Tournament, which contains an array of Teams. I have serialized an intance 'a' of the Tournament class into a .dat file.
try{
ObjectOutputStream oTourn = new ObjectOutputStream(new FileOutputStream(jTextField1.getText()+".dat"));
oTourn.writeObject(a);
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e.toString(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
This .dat file is then loaded from another JFrame, and read into another instance "t" of Tournament. "t.Teams" is sent to the constructor of a new JFrame, TeamStats, which contains the ComboBox:
Tourn t;
try{
ObjectInputStream inTeam = new ObjectInputStream(new FileInputStream(jTextField2.getText()+".dat"));
t = (Tourn) inTeam.readObject();
switch(jComboBox1.getSelectedIndex()){
case 0:
TeamStats tsw = new TeamStats(t.Teams);
tsw.setVisible(true);
break;
}
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e.toString(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
In the Team Stats form, I have declared the ComboBoxModel, and the constructor takes an array of Teams. I have attempted to create the ComboBox in the following way:
ComboBoxModel teamBox;
public TeamStats(Team [] theTeams) {
initComponents();
try{
teamBox = new DefaultComboBoxModel(theTeams);
jComboBox1.setModel(teamBox);
}
catch(Exception e){
System.out.println(e.toString());
}
}
When i run the program however, the Combobox is completely blank. No items in it. The list drops down, but there is nothing in it. Help would be appreciated