I am trying to make a row which will contain JCombobox
in a class which extends AbstractTableModel
.
I have a 2D array which is called data. I also use the method getColumnCount()
in order to implement two buttons "Previous" and "Next". I have marked where I think the JCombobox
should be, but I don't know how I should implement in the whole row.
public class SwitchTableModel extends AbstractTableModel{
@Override
public int getRowCount() {
// Standard number of rows
return 3;
}
@Override
public int getColumnCount() {
// Number of columns change according to the data
return data [position].length + 1;
}
public Object getValueAt(int rowIndex, int columnIndex) {
switch (rowIndex)
{
case 0:
return columnIndex == 0 ? "ID" : idArray [data [position][columnIndex - 1]];
case 1:
return columnIndex == 0 ? "Company Name" : company_nameArray [data [position][columnIndex - 1]];
case 2:
return columnIndex == 0 ? "Double" : ...???
default:
throw new Error ();
}
}
public void previous ()
{
position -= 1;
if (position < 0) position = data.length - 1;
fireTableStructureChanged();
}
public void next ()
{
position += 1;
if (position >= data.length) position = 0;
fireTableStructureChanged();
}
}
Any help will be valuable