Hi all, I'm trying to display a jtable in a pop up Jframe and am running into some problems. What i'am trying to do is as follows:
catch a button action event in the main frame and display a pop up frame with a jtable populated with some data. The problem i have is that the jtable is populated with metadata i receive from a website and if i'm receiving many records, then the jtable is not displayed until all the records(metadata) is received from the website. I would like to change it such that as soon as the button event is detected in the main frame, I display the pop up frame along with the jtable and insert/update rows "as and when i receive the data from the website". In another words, i want to display the table and have the records appearing one at a time rather than displaying the jtable only after i receive all records.Below is how i'm trying to do it (but in vain :( ):
.........
//add the table to the popup frame when application is started, but don't display the frame `until button action is //detected`
extraInfoFrame.add(tblMetadata);
extraInfoFrame.setVisible(false);
//handle code for button press; display the popup
private void butMetadataActionPerformed(java.awt.event.ActionEvent evt) {
extraInfoFrame.pack();
extraInfoFrame.toFront();
//frame.setSize(350, 250);
extraInfoFrame.setVisible(true);
//retrieve rows data for the table
for(int i=0;i<len;i++){
Object[] data=new Object[4];data=getMetadata();
//get model and insert row
((javax.swing.table.DefaultTableModel)tblMetadata.getModel()).insertRow(i,data);
//tried something to notify the view abt change in table data
((javax.swing.table.DefaultTableModel)tblMetadata.getModel()).fireTableRowsInserted(0, 0);
tblMetadata.revalidate();
tblMetadata.repaint();
}
}
Have been racking my head to try and figure something out. A sample example would be greatly appreciated.