0

I am using JXTable to display a list of records.

  • When I click "Refresh" button, I want the JXTable to be refreshed to display the newly inserted records.

  • And also when I click "Add new Row" button, a new row must be added to JXTable.

How can I do these? I am unable to find any useful reference or samples. Please guide me.

kleopatra
  • 51,061
  • 28
  • 99
  • 211
brainless
  • 5,698
  • 16
  • 59
  • 82
  • 1
    Update table model class instance, it will notify table view instance and it will be refreshed. JTable is implemented according to MVC design pattern, and JTable representation is view, but data that is displayed is 'model'. Update 'model' and it will notify 'view' component. –  Aug 07 '12 at 10:50
  • @Rafael Osipov: Thanks for the response. FYI. I am using JxTable and not JTable. – brainless Aug 07 '12 at 10:56
  • 1
    AFAIK it is an extended version of JTable and the main concept is the same. –  Aug 07 '12 at 12:19

1 Answers1

4

It works the same as with a regular JTable, which is all explained in the table tutorial. But to answer your questions:

  • There is no need for a 'Refresh' button, unless the 'Refresh' button updates the TableModel. The moment you update your TableModel you should fire the appropriate events so that the JTable is aware of the changes made to the model. At that moment, the JTable will refresh itself automatically. If your TableModel extends from DefaultTableModel there are already methods available which take care of the events (like e.g. insertRow)
  • Inserting a row means adding a row to the TableModel + firing the appropriate events. If you use a DefaultTableModel, you can use the available API of the DefaultTableModel
Robin
  • 36,233
  • 5
  • 47
  • 99