문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top