Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you premonition is right, you need to adhere to Swing threading rules. </p> <p>So what to do?</p> <p>First, I am not sure how your app is designed exactly. You say that you have a main frame with a bunch of rows, and potentially each could potentially call one of 9 classes, and they all look like the one above. It seems that these classes will generate their own <code>JFrame</code>. I guess that this new frame is solely used for the progress bar. I will assume that this is the design and will suggest accordingly.</p> <p>I suggest that you perform a couple actions in instances of <code>Runnable</code>, and you drop those <code>Runnable</code> instances into <code>SwingUtilities.invokeLater</code> to have them run on the EDT. At the same time, I would take the time to reorganize your code for ease if reading.</p> <ol> <li>move the creation of your GUI bits into a method: </li> </ol> <pre>public void createComponents () { SwingUtilities.invokeLater(new Runnable() { public void run() { //Create all components progressFrame = new JFrame("Calculation Progress"); progressFrame.setSize(300, 100); pane = progressFrame.getContentPane(); pane.setLayout(null); progressFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); progressBar = new JProgressBar(0, iterations); //Add components to pane pane.add(progressBar); //Position controls (X, Y, width, height) progressBar.setBounds(10, 10, 280, 20); //Make frame visible progressFrame.setResizable(false); //No resize progressFrame.setVisible(true); } }); } </pre> <ol> <li>Then I would methodize the two GUI actions that you have in your calc:</li> </ol> <pre> private void updateProgressBar(final int i) { SwingUtilities.invokeLater(new Runnable() { public void run() { progressBar.setValue(i); //no need for the following //progressBar.repaint(); } }); } private void killDialog() { SwingUtilities.invokeLater(new Runnable() { public void run() { progressFrame.setVisible(false); } }); } </pre> <ol> <li>Finally, replace where the code contained in these new methods with calls to the methods.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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