Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add a new row to JTable

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


(obviously untested but)
hth
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic