Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I second camickr's recommendations, but regarding this code snippet:</p> <pre><code>StatisticPanel::paintComponent(Graphics g) { clearStatisticButton.setEnabled(stat.hasEntries()); minValueLabel.setText(stat.getMinValue()); super.paintComponent(g); } </code></pre> <p>You have non-painting methods in your paintComponent method (the first two methods), and that shouldn't be as 1) you want this method to be as lean and fast as possible and thus have only painting-related code, and 2) you do not have aboslute control of when this method is called or even if it is called, and so non-painting related code and program logic does not belong in there. For these reasons, I strongly urge you to get them out of there, but instead should be called separate from paintComponent, but as with most Swing code, on the EDT.</p> <p><strong>EDIT 1</strong><br> I'm not a professional, but how about if you gave your StaticPanel a method similar to this:</p> <pre><code> public void doMyUpdate() { if (SwingUtilities.isEventDispatchThread()) { clearStatisticButton.setEnabled(stat.hasEntries()); minValueLabel.setText(stat.getMinValue()); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { clearStatisticButton.setEnabled(stat.hasEntries()); minValueLabel.setText(stat.getMinValue()); } }); } repaint(); // if the paintComponent method has more than just a super call. } </code></pre> <p><strong>EDIT 2</strong><br> Also, please have a look at this thread: <a href="https://stackoverflow.com/questions/2684049/check-if-thread-is-edt-is-necessary">check-if-thread-is-edt-is-necessary</a></p>
 

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