SwingWorker ProgressBar

Several things: There are four rules to follow with SwingWorker. You can refer to this diagram: . So, this code: @Override public String doInBackground() { //download here label.setText(“test”); violates that rule. Your label.setText() should be moved to the constructor. To send “updates” to Swing components (like your progress bar) you want to use the process() … Read more

SwingWorker does not update JProgressBar without Thread.sleep() in custom dialog panel

The setProgress() API notes: “For performance purposes all these invocations are coalesced into one invocation with the last invocation argument only.” Adding Thread.sleep(1) simply defers the coalescence; invoking println() introduces a comparable delay. Take heart that your file system is so fast; I would be reluctant to introduce an artificial delay. As a concrete example … Read more

How to customize a JProgressBar?

There are a number of ways you might achieve this, one of the better ways would be to create a custom ProgressBarUI delegate which paints itself the way you want, for example… public class FancyProgressBar extends BasicProgressBarUI { @Override protected Dimension getPreferredInnerVertical() { return new Dimension(20, 146); } @Override protected Dimension getPreferredInnerHorizontal() { return new … Read more

How to change JProgressBar color?

I think that these values are right for you UIManager.put(“ProgressBar.background”, Color.ORANGE); UIManager.put(“ProgressBar.foreground”, Color.BLUE); UIManager.put(“ProgressBar.selectionBackground”, Color.RED); UIManager.put(“ProgressBar.selectionForeground”, Color.GREEN);

Java: JProgressBar (or equivalent) in a JTabbedPane tab title

For earlier versions, you might try addTab() with a suitable implementation of Icon used to indicate progress. import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class JTabbedTest { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { private final JTabbedPane jtp = new JTabbedPane(); public void run() { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); … Read more

JProgressBar won’t update

It’s difficult to tell from the code sample you’ve provide… The main cause of this problem is trying to update the UI while blocking from the Event Dispatching Thread (EDT). It’s important to NEVER do any long running or blocking operations within the EDT as this will prevent repaint requests from been acted upon. For … Read more