i have created an app which reads lines from a .txt file, splits the line at a " " and then stores them in a ArrayList which then gets put in a JTable.
i created 27 columns and named them... now i want to add an extra column on the end but make each row a JComboBox.
i added an extra column in my JTable called HI:
private class MyTableModel extends AbstractTableModel {
private String[] columnNames = {"Name" , "Age", "Pos", "Nat", "St", "Tk", "Ps", "Sh", "Ag", "Kab", "Tab", "Pab", "Sab", "Gam", "Sub", "Min",
"Mom", "Sav", "Con", "Ktk", "Kps", "Sht", "Gls", "Ass", "DP", "Inj", "Sus","HI"};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return rosterList.size();
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col)
{
return rosterList.get(row)[col];
}
}
i tried using this:
int index1 = 27;
TableColumn col1 = table.getColumnModel().getColumn(index1);
javax.swing.JComboBox comboBox = new javax.swing.JComboBox();
ArrayList list = new ArrayList();
list.add("GK");
list.add("DFC");
for (int i = 0; i < list.size(); i++)
{
comboBox.addItem(list.get(i));
}
col1.setCellEditor(new javax.swing.DefaultCellEditor(comboBox));
it wont compile and i get this error:
java.lang.ArrayIndexOutOfBoundsException: 27 >= 27
i think its got something to do with the reading of the .txt file because it only has 26 columns in the file.
how would i fix it?