Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top