Question

I have created a JTable table

String[] ColumnNames = { "Name" , "Father Name", "D.O.B" };
Object[][] data;    
DefaultTableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable(model);
JScrollPane pane = new JScrollPane(table);
JPanel panel = new JPanel();
panel.add(pane);

So what I want to do is when I populate Object data (not initialized yet, but it get populated correctly no issue here), table rows should also be updated with new data and when I search again and If no result is found then table should be empty.

In short I want to update table every time I hit "Search" button. Increase/Decrease in rows.

Was it helpful?

Solution

Create a new TableModel and set it to the instance of JTable on the view. The change will automatically update the table.

This will require you to make table an instance variable within the class...

How to use tables might help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top