Link to home
Start Free TrialLog in
Avatar of geronimo2
geronimo2

asked on

How can I add rows using an AbstractTableModel

Using Swing jdk1.2
How can I add a row like you would with DefaultTableModel when I am using the
AbstractTabeleModel
I have created aTwo Dimensional array to store the row and column data
but i need to add a few more rows after the table had been constructed
With the DefaultTableModel you can just create a one dim array for the row data and add it to the model.
Basically so I need my Two dim Array to expand
but i havent a clue where to go now
Any help greatly appreciated
Regards Dave


Avatar of kylar
kylar

Well, what you are describing is not possible. An Abstract table model can't add a row. but the table model that you are storing as an AbstractTableModel isn't really an AbstractTableModel, it's a concrete instantiation of another class that implements it. so you need to make sure that the concrete implementation has a method like addRow(Vector RowToAdd) then cast it like this:

public class tableManipulator{

public tableManipulator(){
DefaultTableModel myModel = new DefaultTableModel();

//assume there is data in the table model

doTableRowAdd(myModel);



}
public void doTableRowAdd(AbstractTableModel abstractModel){

//now here you are getting an 'Abstract' table model, but it's really
//a concrete class (DefaultTableModel). so what we do is something like this:

Vector newRowData = new Vector();
//assume we add data to this vector;

//now we cast the abstract to a default, since we know what it is really:

DefaultTableModel dtm = (DefaultTableModel)abstractModel;

//then we add to it
dtm.addRow(newRowData);

}

}
}

If that's not what you want, I'm sorry :) post your code and we'll see what we can do
ASKER CERTIFIED SOLUTION
Avatar of fmaritato
fmaritato

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Which means, don't use default table model but implement your own. It is easy and there lots of examples on the sun site.

  Nik
Avatar of geronimo2

ASKER

Note Sorry about delay in responding as I have Limited Internet access here in college.

:) fmaritato
Thanks fmaritato I sorted it out by using DefaultTableModel.
Initially I had implemented by own AbstractTableModel similiar to the one you had outlined above but I had problems with rendering the cells which I have now sorted out.
It was your suggestion about using Vectors etc which helped me.Thanks alot
Regards Dave.

:)kylar
Thanks for suggestion there is a seperate 50 points for you to claim also.
Sound lads Thanks alot for the help
Regards Dave



Note Sorry about delay in responding as I have Limited Internet access here in college.

:) fmaritato
Thanks fmaritato I sorted it out by using DefaultTableModel.
Initially I had implemented by own AbstractTableModel similiar to the one you had outlined above but I had problems with rendering the cells which I have now sorted out.
It was your suggestion about using Vectors etc which helped me.Thanks alot
Regards Dave.

:)kylar
Thanks for suggestion there is a seperate 50 points for you to claim also.
Sound lads Thanks alot for the help
Regards Dave