EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Adding a row


Author: Zafir Anjum

Note that if you are using your own subclass of AbstractTableModel(), this doesn't apply to you. Your TableModel should provide such a feature.

Here's the code snippet you can use to insert a blank row at the end of the table.


if( table.getModel() instanceof DefaultTableModel )
 {
	int cols = table.getModel().getColumnCount();
	((DefaultTableModel)table.getModel()).addRow(new Object[cols]);
 }

In the code above, we make a check whether the table model is an instance of a DefaultTableModel. This is required because when you create JTable giving it initial data, Swing creates an anonymous subclass of AbstractTableModel.

If you are using your own TableModel, make sure that addRow() is supported.

Posted On: 25-Feb-1999

internet.commerce