How do I pre-populate the first column of a JTable using AbstractTableModel?
I want to put in time-slots in the first column and then populate the other columns with something else.
Ok so the ChannelTableModel will be used by JTables in the GUI. Basically it sets time slots of 30mins from 6.30 - 24:00. The time slots have to be put in the first row of a JTable
In some way I need to set a variable 'row' to get the row values in the AbstractTableModel, which I'm finding difficult to do.
Below is the code so far.
Code:
import java.util.List;
import javax.swing.table.AbstractTableModel;
public class ChannelTableModel extends AbstractTableModel
{
public ChannelTableModel(List<Program> schedule)
{
this.channel= schedule;
}
public int getColumnCount()
{
return 3;
}
public int getRowCount()
{
return 37;
}
public Object getValueAt(int rowIndex, int columnIndex)
{
switch (columnIndex)
{
case 0: return 6+((row*30) / 60)+":"+(row % 2 == 0 ? "00" : "30") + " - " + (6 +(((row+1)*30) / 60)+":"+(row % 2 != 0 ? "00" : "30"));
default: return "Not Available.";
}
}
}
How do I create the variable "row" to make the TableModel workable ?