Working with several custom table models avoiding repetitive code

Like other Swing models (i.e.: DefaultComboBoxModel, DefaultListModel) we can use Generics in order to create a flexible and reusable table model, also providing an API to work with user-defined POJO’s. This table model will have the following special features: It extends from AbstractTableModel to take advantage of table model events handling. Unlike CustomerTableModel shown above, … Read more

JTable not showing

Invoking setModel() on the table should be sufficient, but you might call fireTableStructureChanged() on the model explicitly as a way to help sort things out. Also, verify that you are working on the event dispatch thread. Addendum: Here’s an sscce that shows the basic approach. import java.awt.Dimension; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JComboBox; … Read more

AbstractTableModel GUI display issue

Because database access is inherently asynchronous, you’ll surely want to retrieve rows in the background to avoid blocking the event dispatch thread; SwingWorker makes this relatively easy. Fetch rows in your implementation of doInBackground(), publish() interim results, and add them to the table model in your implementation of process(). A complete example that outlines the … Read more