Hello good day.
Here is my problem:
I have retrieved some a couple sets of data from my sql database and saved them in ArrayLists of (custom)types <Student> and <Subject>. I am using a single Table. I want to create a custom AbstractDataModel that displays the data from the ArrayList<Student>. The data that comes from ArrayList<Student> are simply Strings, and this constitutes half of the table. The other half of the table is populated by the user editing the cells via JComboBox editor. These choices are used to carry out calculations in order to populate the ArrayList<Subject>.
Problem is, all of this is just in my head. But I can't seem to get this coded. So far I have created the AbstractTableModel and added a TableCellEditor to a few columns so that they are edited via JComboBox's. But whenever I select a choice it doesn't display within the cell. My code seems to be clashing.
ArrayList<Student> applicants=new ArrayList<Student>(300);//Stores all information from the applicants
ArrayList<Subject> subjects=new ArrayList<Subject>(15);
String[] theSubs={"---","Biology","Additional Math","Geography","History","Spanish","Information Tech.","Technical Drawing","French","Physics","Chemistry","Principles of Accounts","Principles of Business"};
DefaultComboBoxModel subCBXmod=new DefaultComboBoxModel(theSubs);
JComboBox studentComboBox=new JComboBox(subCBXmod);
DefaultCellEditor editor=new DefaultCellEditor(studentComboBox);
...
/**
*An inner class
*/
public class TableDWModel extends AbstractTableModel{
public TableDWModel()
{
fireTableDataChanged();
}
@Override
public int getRowCount()
{
return applicants.size();//The student is really the subject of the Table. They determine how many rows there will be.
}
@Override
public int getColumnCount()
{
return tableColumns.length;
}
@Override
public String getColumnName(int col)
{
return tableColumns[col];
}
@Override
public Object getValueAt(int row, int col)
{
Student st=new Student();
st=applicants.get(row);
switch(col)
{
case 0:
return (st.getFirstName()+" "+st.getLastName());
case 1:
return st.getFormClass().getForm();
case 2:
return st.getGender();
case 3:
return st.getShift();
case 4:
return st.getTotalSubjects();
case 5:
//Clueless!
}
return null;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return (columnIndex >= 3);
}
And this is the design of my table:
So how can I accomplish sewing these pieces together please?