Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to reflash the data in JTable?  RSS feed

 
Jack Yang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,
How to reflash the JTable so after I book or cancel,it can reload the data automaticlly?
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should write a custom table model. changes to this model will be automatically visible (through event firing) in the table. see the swing tutorial on table models.
cheers
 
Lennie B
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jack,
you can build your JTable using TableModel with .query() method, where
you actually fill table with data. Then after doing somthing with data
all you have to do is call this method again - it will reload the table.
public class someTableOrerating
{
private myTableModel tblModel;
private JTable tbl;
...

public someTableOrerating()
{
tblModel = new myTableModel();
tblModel.query(); //for the first time
tbl = new JTable(tblModel);
...
}
...
tblModel.query();//after doing something
}
class myTableModel extends AbstractTableModel
{
private Vector tableData;
public myTableModel()
{
tableData = new Vector();
}
public void query()
{
...
//generating or retrieving data somehow, i.e.
while ( ... ) {
String[] record = new String[number_of_columns];
record[0] = ...;
record[1] =...;
...
tableData.addElement(record);
}
}
}
Best regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!