Reputation: 16060
I have a JTable
populated from the data structure List<String>
. Also I have a button "Create New Field" that is used to create new entries in List. I can add new entry to List<String>
, however I don't know how to refresh JTable
after adding new entry.
Upvotes: 0
Views: 426
Reputation: 31
1.I have made a new project in that i have selected a new frame and drag a table,a label, a text field and a button from the swing controls to your frame.
2.create a table in back end
3.Download rs2xml jar file from this link Download rs2xml.jar
Add it to the project library
4.Then connect MySQL
5.Then create a update function type the following code...
rs=statement.executeQuery("select * from details");
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
6.In the buttons action event type the following and call the update function.
Object name=jTextField1.getText();
String sql="insert into details (name) values('"+name+"')";
int resultset=statement.executeUpdate(sql);
You can follow this tutorial:---
How to refresh jTable after adding new entry
Upvotes: 1
Reputation: 21224
You have to use tableModel.fireTableDataChanged()
. Or if only a very small part (i.e. one cell) has been updated in the table: tableModel.fireTableCellUpdated(x,y)
.
According to the comments you need to write your own small TableModel
.
AbstractTableModel
list.size()
list.item(row)
fireTableDataChanged()
Upvotes: 1
Reputation: 304
Use the observer pattern.
http://en.wikipedia.org/wiki/Observer_pattern
Your table model should be an observer to your list. So that when you list data changes the table will be updated.
Upvotes: 0