Exception in Java UiThreadingViolationException

2

I have done a project with LookAndFeel Substance , in it I have a thread that is updating periodically a JProgressBar , the problem is that in the function JProgressBar.setValue(1) and JProgressBar.setMaximum(10) the following exception occurs:

org.pushingpixels.substance.api.UiThreadingViolationException: Component state change must be done on Event Dispatch Thread
    at org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities.testComponentStateChangeThreadingViolation(SubstanceCoreUtilities.java:2072)
    at org.pushingpixels.substance.internal.ui.SubstanceProgressBarUI$SubstanceChangeListener.stateChanged(SubstanceProgressBarUI.java:87)
    at javax.swing.JProgressBar.fireStateChanged(JProgressBar.java:729)
    at javax.swing.JProgressBar$ModelListener.stateChanged(JProgressBar.java:652)
    at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:364)
    at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:302)
    at javax.swing.DefaultBoundedRangeModel.setMaximum(DefaultBoundedRangeModel.java:219)
    at javax.swing.JProgressBar.setMaximum(JProgressBar.java:898)

I want to know how I can correct this problem, or maybe suppress it , since it does not impact my layout.

    
asked by anonymous 09.02.2015 / 19:05

1 answer

3

The Victor gave me the hint in the comments and I went after the link that he passed me, after deepening my research I was able to understand the problem with that other link .

Below is an example of the class I've done to update my JProgressBar . Note that the spell is in SwingUtilities.invokeLater .

class AtualizaComponente implements Runnable {
    @Override
    public void run() {
        while (true) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    if (jProgressBar1.getValue() < jProgressBar1.getMaximum()) {
                        jProgressBar1.setValue(jProgressBar1.getValue() + 1);
                    } else {
                        jProgressBar1.setValue(0);
                    }
                }
            });
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
    
23.02.2015 / 16:44