Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you update a JDialog with new information?
    text
    copied!<p>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.</p> <p>An example of the format of the text file:</p> <pre><code>*/ Account ID : 8 digit number Money Charged : Integer &lt; $10 Values separated by \t /* Account Id Money Charged ---------- -------------- 731298 3 359412 5 624937 1 </code></pre> <p>So when the button is clicked, it reads each line and puts each id into a map and increases the charges of the accounts.</p> <p>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 &amp; JTable appears.</p> <p>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 <code>repaint()</code> or <code>validate</code> but those didn't seem to do the trick.</p> <p>Here is the order I'm thinking it should be done:</p> <pre><code>//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 } </code></pre> <p><em><strong>So my overall question is simple:</em></strong> 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)?</p> <p>If needed, I can provide source. Not sure it's really needed though</p> <p><em><strong>Edit</em></strong></p> <pre><code>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 } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload