Originally posted by John Ellis:
I'm new here. Let me know if a different style of posting works better.
Welcome to JavaRanch.
This posting style is fine. You gave useful information (too many people just briefly give their problem, giving details helps, and makes your post more likely to be answered).
Originally posted by John Ellis:
I would like to add a blank row to the bottom of a JTable so the user can enter new data into the blank row of the table. This data will then be read and used to update the table model and the database. I do not want to use a pop-up input frame. The table is generated through an SQL statement sent to a postgresql database. The resultset that is produced by the query is used as the data for the table model. My create statement in by table model is:
Statement st = db.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultsSet.CONCUR_UPDATABLE);
I have tried extending both the DefaultTableModel and the AbstractTableModel. The DefaultTableModel has an addRow method, but when I use it as follows, it gives an arrayIndexOutOfBoundsException. I am not sure how the data is represented in the tableModel - Vectors or Object[].
tableMod = new TheTableModel(db,query);
Vector row = new Vector();
tableMod.addRow(row);
The table displays correctly when I drop the Vector and addRow lines above, but of course, I don't get the blank row.
Well, consider creating your own model. Simply extend the AbstractTableModel and use a Vector as the underlying dataset (what will be appropriate depends on your needs: how often you add, remove, insert, sort, access, etc). You'll probably also want to create a container class to hold the entire row set.
If you're really motivated, you can get the
Java source code and look at how the DefaultTableModel is implamented.
--Mark