Refresh table in parent frame when child closes

I'm trying to refresh a table in a parent frame when the child frame is closed, by clicking the save button.

Code to setup parent frame table:

sorter =new TableSorter(new MyTableModel());

tbl_Applicators.getTableHeader().setReorderingAllowed(false);

tbl_Applicators.setModel(sorter);

class MyTableModelextends AbstractTableModel{

public MyTableModel()throws Exception{

columnNames = dataHandler.getApplicatorColumns();

data = dataHandler.getApplicatorTable();

}

publicint getColumnCount(){

return columnNames.length;

}

publicint getRowCount(){

return data.length;

}

public String getColumnName(int col){

return columnNames[col];

}

public Object getValueAt(int row,int col){

return data[row][col];

}

publicboolean isCellEditable(int row,int col){

returnfalse;

}

}

Code in parent frame to create child frame:

publicvoid but_Add_actionPerformed(ActionEvent e){

JFrame add;

if ( ok to make frame ){

add =new Edit_Applicator("Add Applicator", 370, 500, dataHandler, true, sorter);

add.addWindowListener(new java.awt.event.WindowAdapter(){

publicvoid windowClosing(WindowEvent winEvt){

do things

}

publicvoid windowClosed(WindowEvent winEvt){

do things

}

});

}

}

Code in child to close window:

publicvoid but_Save_actionPerformed(ActionEvent e){

writenew data to database

this.dispose();

}

the data in the table is stored in a database, and i need to refresh the table when the data is saved from the child frame

[3735 byte] By [ChisMa] at [2007-11-26 14:34:03]
# 1

If data is store in a database then why did you write your own TableModel using 2 dimensional arrays to hold the data? How do you know how many rows and columns will be in the database?

Use the DefaultTableModel. It supports dynamic table sizes.

If you want to refresh the table you simply create a new TableModel and then use:

table.setModel( refreshedModel );

camickra at 2007-7-8 2:30:04 > top of Java-index,Desktop,Core GUI APIs...
# 2
i'm using the tablesorter class so i needed to make my own tablemodel
ChisMa at 2007-7-8 2:30:04 > top of Java-index,Desktop,Core GUI APIs...
# 3
> i'm using the tablesorter class so i needed to make my own tablemodel No you don't.
camickra at 2007-7-8 2:30:04 > top of Java-index,Desktop,Core GUI APIs...
# 4
alright. would you be able to show me an example where they bring in the database info and store it in a tablemodel?
ChisMa at 2007-7-8 2:30:04 > top of Java-index,Desktop,Core GUI APIs...
# 5
Search the forum for examples that use the classes you are interested in. Keywords like "resultset jtable defaulttablemodel" should do the trick.
camickra at 2007-7-8 2:30:04 > top of Java-index,Desktop,Core GUI APIs...