Title: RE: how to initialize rows in table

This is a classic mistake in coding a remove loop. You are changing the index and no. of elements at the same time. So, in the second iteration removeRow(1) does not do anything as there is only one row (and the no. for it is 0). Use removeRow(0) instead or write the loop in reverse order.

HTH,

/Shrikant

-----Original Message-----
From: Ravi Prakash [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 03, 2001 2:33 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: how to initialize rows in table


Hi ,

I am using the table model in my jtable.  I am getting the table model
by the following code.

AlarmTableModel errorModel = (AlarmTableModel)errorTable.getModel();
errorModel.init();

The problem is the when the table has 2 rows of data, the init
method(the code is below) initializes only one row and the other row is
visible, the same happens
randomly like if there are 10 rows of datas of intialized, if i call
init only 5 rows removed and the rest 5 displayed from the 0th row...

could any one suggest how to initialize the table, i dont want to use
setValue method to initialize.......

Thxs




class AlarmTableModel extends DefaultTableModel
 {
     int rowCount = 0;
     public AlarmTableModel(int r, int c)
     {
         super(r, c);
         init();
     }

        //clearing the data's from the table
     public void init()
     {
      for(int i = 0;i < rowCount;i++)
      {
          this.removeRow(i);
         }
         rowCount = 0;
     }

     public int getEnteredRowCount() {    return rowCount;  }

     public void setValueAt (Object aValue, int row, int column)
     {
         String cellValue = null;
         if (aValue instanceof String)
      {
          if (row >= this.getRowCount()) return;
          cellValue = (String)aValue;

                super.setValueAt(cellValue, row, column);
                fireTableDataChanged();
          if (row >= rowCount) rowCount = row+1;

      }
     }

     public boolean isCellEditable(int row, int column)
     {
         return false;
     }
 }



_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to