For example, Application 1 may have three columns with the data types string, integer, and boolean.Application 2 may have four columns with the data types string, string, float, and integer.The JTable is pretty oblivious to both these facts.A "row" in a table model can and will look very different from application to application.Each element within the vector reflects the data type of the database column retrieved into it.To add or insert a row, the vector must first be queried about what data types it contains.In Listing 2, the vectors that make up the table model are updated with the new value for the cell.
Before I discuss the login needed for real database updates, I'll discuss the groundwork involved.For example, if a cell value is "Cheeseburger" and the user types "Hotdog" over it, the new value is displayed only when that current cell has the focus.As soon as the user tabs to another cell, the old value is restored. Remember, the programmer is responsible for all behavior.These data types can then be built and added into another vector.This resulting vector can then be added to our table model, effectively adding a row.The concept of a "row" really exists only for the beholder.As far as Java is concerned, a row is a vector of supporting classes.With that in mind, there should be a method called add Row() or insert Row(), for example, available for the table model, right? To understand why, you must first see what a "row" really is.Because the table model contains the data for the JTable, it also controls and is aware of what a row looks like.Any GUI you write using a JTable should include it. Remember, the JTable is merely the view of the data.Most functionality, including the addition of rows, must occur in the table model. If you think about it, the absence of such built-in Java methods makes sense.