Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem making a JProgressBar update values in Loop (Threaded)
    primarykey
    data
    text
    <p>Am trying to get my program to update the progress bar values constantly within a method while performing some operations. However this does not happen until the end, and the UI freezes. </p> <p>After looking around to similar questions with my problems, I tried to implement the accepted solutions (Using threads) however I cannot get it to work correctly. Is just like if they where not there.</p> <p>My program contains several classes, the <code>Main</code> being the one automatically created by netbeans on the JFrame <em>Design</em> mode, so there are certain things such as the <code>static void main</code> and the <code>public Main</code> that am not really sure of some of its contents. Under i will put the snippets of those methods, together with my thread implementation.</p> <pre><code>public class Main extends javax.swing.JFrame implements ActionListener, Runnable{ // I added implements ActLis, Runn..... ... static Main _this; // I included this variable ... public static void main(String args[]) { Main m = new Main(); // Added by me new Thread(m).start(); // Added by me java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Main().setVisible(true); } }); } ... public Main() { initComponents(); _this = this; // Added by me } ... // I also included these 2 methods in the class public void actionPerformed(ActionEvent e) { synchronized(this){ notifyAll(); } } public void run() { try{synchronized(this){wait();}} catch (InterruptedException e){} progressBar.setValue(50); } ... private void buttonPressed(java.awt.event.MouseEvent evt) { for(int i=0; i&lt;=100; i++) { for(int j=0; j&lt;=5; j++) { // does some work } run(); } } </code></pre> <p>All the things that I commented as <code>I added...</code> are things that I putted according to tutorials and answers I have seen online, but nothing seems to work and it feels like I have tried close to a million different combinations... </p> <p>Thanks in advance for helping out.</p>
    singulars
    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.
 

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