Question

I'm developing a software for my friend.I have developed 90% of my project and my problem is I have a table which I fill with data in database.I have used a custom table model to fill jtable. It fills data perfectly but the problem is it doesn't contain proper column header instead of that it contain A,B,C for column headers .

here is my custom table model class.

 public class SellUpdateModel extends AbstractTableModel
{

private Vector<Vector> data;

public SellUpdateModel(String Jid)
{

    data = new Vector<>();
    data = new JobDetailsDAO().get_ItemDescriptionAndQuantity(Jid); //Retrive data from databse and fill it to vector.
}

@Override
public boolean isCellEditable(int rowIndex, int columnIndex)
{
    return false; // does not allowed to edit cells 
}

@Override
public int getRowCount()
{
    return data.size();
}

@Override
public int getColumnCount()
{
    return 3;
}

@Override
public Object getValueAt(int rowIndex, int columnIndex)
{
    return data.elementAt(rowIndex).elementAt(columnIndex);
}

public SellUpdateModel deleteRow(int row, Vector pData)
{
    data.remove(data.elementAt(row)); // remove a record from vector
    data.add(pData);                // add a record to vector
    return this;
}
}
Was it helpful?

Solution

You have to override getColumnName(int columnIndex).

public class SellUpdateModel extends AbstractTableModel {
 private final String[] tableHeaders = {"X", "Y", "Z"};


 @Override
 public String getColumnName(int columnIndex) {
  return tableHeaders[columnIndex];
 }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top