I have a Gui which allows the user to click a button and view the contents of a text file. The issue is that the file can be rather large (100,000+ rows of data) and can take upwards of 15 seconds to read and display in a table.
An example of the format of the text file:
*/
Account ID : 8 digit number
Money Charged : Integer < $10
Values separated by \t
/*
Account Id Money Charged
---------- --------------
731298 3
359412 5
624937 1
So when the button is clicked, it reads each line and puts each id into a map and increases the charges of the accounts.
Once it is finished it will place a JTable inside a JDialog with the information. However, as soon as the button is clicked, the user could be confused as to what the program is doing as I’ve experienced upwards of 10-15 seconds of delay before the JDialog & JTable appears.
So is there a way to make the JDialog appear with a string letting the user know that it is creating the table? (I thought it would be done using one of the JDialog methods such as repaint() or validate but those didn’t seem to do the trick.
Here is the order I’m thinking it should be done:
//Psuedo-code
actionPerformed {
create frame
display label that lets user know its creating table
read text file
create map and place values
remove label
update dialog with table // unsure what to do to update it properly
}
So my overall question is simple:
Is it possible to inform the user that it is currently calculating the data (via JLabel in the JDialog) and once the data is read, display the JTable (by updating the JDialog)?
If needed, I can provide source. Not sure it’s really needed though
Edit
public void actionPerformed(ActionEvent event) {
JFrame frame = new JFrame();
JDialog dialog = new JDialog(frame, "Account Charges", true);
JLabel label = new JLabel("Currently calculating the charges")
dialog.getContentPane().add(label); //add waiting label
dialog.setVisible(true);
readData(myFile); //read file and create table
dialog.getContentPane().remove(label); //waiting label no longer needed
dialog.getContentPane().add(myJtable); //update dialog with the table
}
1)
I have a Gui which allows the user to click a button and view the contents of a text file.2)
The issue is that the file can be rather large (100,000+ rows of data) and can take upwards of 15 seconds to read and display in a table.3) //Psuedo-code
actionPerformed {
create frame– not JFrame re_use existingJDialog, sure better could beCardLayoutdisplay label that lets user know its creating table– no idea let it beread text file– use SwingWorker with JProgressBar, to transform data and put that to the TableModel, use batch for update of TableModel f.e. every 50rows, look for paginations for JTable, then you’ll display only required numbers of rows, not 100k, this could be crazy 🙂create map and place values– could be useless because you are storing all required informations in the TableModelremove label– no idea let it beupdate dialog with table– Jtable could be updated immediatelly from SwinWorker, Swing GUI could be accesible for all Mouse or KeyBoards inputs, never waiting, nor delay at 10-15sec}