Problem implementing the abstractTableModel


    I have constructed a JTable using the abstractTableModel but I am having problem implementing some of the mehods of the AbstractTableModel such as setValueAt and getValueAt. Also I need to create a method to insert a row.

Here is a snippet of my code:

public class DataFileTableModel extends AbstractTableModel {
 protected Vector data;
 //protected Vector columnNames ;  
 protected String datafile;
 private Vector tableOfVectors = new Vector();  
 private Vector columnNames;
 Vector data_vector = new Vector();

 public DataFileTableModel(String f){
   datafile = f;

 public void initVectors() {
     String aLine;
     //tableOfVectors = new Vector();
     columnNames = new Vector();
       Process ls_proc = Runtime.getRuntime().exec(datafile);
       BufferedReader br = new BufferedReader(new InputStreamReader( ls_proc.getInputStream()));  
        //extract coumn names
       StringTokenizer st1 =
           new StringTokenizer(br.readLine(), "|");
            //extract data
           while ((aLine = br.readLine()) != null) {  
             StringTokenizer st2 = new StringTokenizer(aLine, "|");
                    tableOfVectors.add(st2.nextToken() );
   catch (Exception e) {

 public int getRowCount() {
   return tableOfVectors.size() / getColumnCount();

 public int getColumnCount(){
   return columnNames.size();

 public String getColumnName(int columnIndex) {
   String colName = "";

   if (columnIndex <= getColumnCount())
      colName = (String)columnNames.elementAt(columnIndex);

   //return columnNames[columnIndex];
   return colName;
 public Class getColumnClass(int columnIndex){
   return String.class;
 public boolean isCellEditable(int rowIndex, int columnIndex) {
   return false;
 public void insertRow(int index, Object[] element)
 public void removeTask(int startRow,int endRow)
      int tempRow = 0;
     int actualRows = 0;

    if (endRow < startRow)
      tempRow = endRow ;
      endRow = startRow ;
      startRow = tempRow ; }

    if (startRow < 0 || endRow > getRowCount())

    actualRows = (endRow - startRow) + 1 ;

    // determine the starting point (cell) to start deleting at //
     int colCount = getColumnCount() ;  
     int cell = startRow * colCount ;

    // determine the total number of cells to delete //
    int totColCount = (getColumnCount() * actualRows) ;

    for (int d = 0; d < totColCount; d++)
      tableOfVectors.remove(cell) ;

    fireTableRowsDeleted(startRow,endRow) ;

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Well you know what i'd say about that don't you? ;-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DefaultTableModel supplies the functionality of adding/deleting rows. If you extend DTM is there any reason why you would need to override set/getValueAt?
For that matter, is there any need to *extend* DTM as opposed to simply creating one?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.