I'vve been trying to google this, but most people ask questions related to a large single table, my problem is a bit different.
Sorry I cant provide working code, my program is a bit complex, but if someone can point me in a direction ill try to find a solution.
In short, I have a very large text file that i read and create objects for each line, eg HeaderRecord or ClaimDetail etc. the current file ends up with about 60,000 objects. I then create JTables for each record, iterate through them and then add them to my scrollpane.
It works great, my problem is that loading this data into memory takes alot! (obviously). But even ignoring that, after the data is loading and the screen pops up its still stuck for like a minute, probably trying to draw all of this is the pane.
The only solution i can think of is to somehow paginate the display. only pulling in a certain number of JTables at a time. I have no idea how to go about this! If someone can please help me out with a suggestion of what to look at i would really appreciate it
Thanks
Update: I implemented a swingworker like this:
private class TableRun extends SwingWorker<Void, JTable> {
private ArrayDeque<FileRecord> fileRecords;
private final GridBagConstraints gc;
private final JPanel parentPanel;
int counter = 1;
TableRun(ArrayDeque<FileRecord> fileRecords, GridBagConstraints gc, JPanel parentPanel) {
this.fileRecords = fileRecords;
this.gc = gc;
this.parentPanel = parentPanel;
}
@Override
protected Void doInBackground() {
Iterator<FileRecord> iterator = fileRecords.iterator();
while (iterator.hasNext()) {
publish(getTabel(iterator.next()));
Thread.yield();
}
return null;
}
@Override
protected void process(final List<JTable> tables) {
Iterator<JTable> iterator = tables.iterator();
while(iterator.hasNext()) {
JTable table = iterator.next();
gc.fill = 1;
parentPanel.add(table.getTableHeader(), gc);
gc.gridy++;
parentPanel.add(table,gc);
gc.gridy++;
System.out.println("Sequence Nr : " + table.getModel().getValueAt(0,1) + " - Counter :" + counter++);
}
}
}
It seems to work... mostly. my problem is that in my JFrame constructor i set
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
so the frame opens up on the entire screen. What i want is as the swingworker completes adding the JTable to my panel in the process method it should add those tables to the panel and display them. so it should display as it gets them all the way up until the entire file is read. This doesnt happen. In fact the display just stays blank until i resize the frame, then it actually displays the tables.
I tried to call Outerclass.this.repaint() from within the process method in order to rapaint my Jframe but that didnt work...
Any advice?
Thanks