Hi all. I have extended the AbstractTableModel in my application and every thing is ok. my application is connected to a database and displayed the results using this table. now, I want to add a button, when I clicked it, a new row should be added to the table (I mean to the JTable component), so I can enter some values how to perform this ??
without a code snippet, it's hard to tell how your component model is setup. Some people prefer to separate 'view', 'controller', and 'model' components, others mix the code inline. If you have required fields, the button should popup a dialog window allowing user to enter those fields. Once you validate what they enter, you can add a new row to the underlying tablemodel, and fire a TableDataChanged() event to trigger the class to update the view. for example
I want to add a row when pressing a jbutton (like the deploytool when you clicked on a jbutton, so a new row added and you entered some values)
Joined: Apr 30, 2004
you could do the same thing, just without a 'requiredField" feature. you would attach a listener to the 'add' button. the listener would execute the method/code to add a new 'row/record' instance to the underlying datamodel and subsequently Fire TableChanged, or TableRowsInserted ... your underlying data model will need to support initializing the row/record with no data, and your tablemodel should 'see' all the fields in the row as editable (i.e. isEditable method always returning true for these rows) if you dig around, you can probably find the 'hooks' for adding your code in the existing table model/view code. hth
The AbstractTableModel does not do any data storage for you, so you must have already added all that stuff to your implementation of AbstractTableModel. So a lot depends on what kind of data structures you have used, vectors or arrays?
The nice thing about Standards is that there are so many to choose from!