The progress bar does not update immediately

I am trying to use both the progress bar and the label to show the progress of a discreet number of operations. Each time I update both options, the shortcut is updated immediately, and the progress bar has a noticeable delay before it changes .

I have a test dialog where, when I click the button, I update both the label and the progress bar to reflect an increase of 1. This happens immediately in the code without any loops or threads being called ( fixing any problems related with threads as a reason ) - a simple change in values. When this happens, the shortcut is updated immediately, and the progress bar waits about half a second before a visual update. This leads to examples where he will say, for example, β€œ2 of 3” when he briefly but noticeably shows 1/3 of the filled bar.

enter image description here

import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ProgressBar; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; public class ProgressBarTest extends Shell { private ProgressBar progressBar; private Label lblXOfX; private Button btnGo; public static void main(String args[]) { try { Display display = Display.getDefault(); ProgressBarTest shell = new ProgressBarTest(display); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } catch (Exception e) { e.printStackTrace(); } } public ProgressBarTest(Display display) { super(display, SWT.SHELL_TRIM); createContents(); } protected void createContents() { setText("SWT Application"); setSize(450, 300); setLayout(new GridLayout()); progressBar = new ProgressBar(this, SWT.NONE); progressBar.setMaximum(3); progressBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); lblXOfX = new Label(this, SWT.NONE); lblXOfX.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); lblXOfX.setText("x of x"); btnGo = new Button(this, SWT.NONE); btnGo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent arg0) { go(); } }); btnGo.setText("Go"); } @Override protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components } protected void go() { int iCur = progressBar.getSelection(); iCur++; if (iCur > progressBar.getMaximum()) iCur = 0; progressBar.setSelection(iCur); lblXOfX.setText(String.format("%s of %s", iCur, progressBar.getMaximum())); } } 

This happens despite using the internal Progress Bar variable to track the value and use that value to update the label.

It is noteworthy that changing the progress bar "Status" to "ERROR" or "PAUSED" fixes the problem.

Is this some kind of animation bug? Is this just a problem with a specific version of Windows , such as the Windows 7 that I am using? Or is it something else?

+7
java windows swt progress-bar
source share
4 answers

It seems like this could be a bug in the Windows ProgressBar version, as the code works on Linux and Mac OS X.

There is code in the Windows version of ProgressBar.setSelection that says it is trying to deal with a problem that sounds like this, but this is only done if the condition is not normal - which may be the reason that it is working with an error and paused state. Fixing them just makes the choice again, so maybe calling setSelection will work twice!

+4
source share

You can follow this tutorial , it describes how you can create Eclipse Jobs to do long tasks besides EDT, and just update the state of your components. Hope this helps, Cheers!

+1
source share

I tested the code you provided using the latest version of SWT (4.3 Final Release - June 5, 2013) under Windows 7 SP 1 and Windows XP SP3. In both cases, the progress bar is updated without delay. Perhaps updating the SWT library will help.

+1
source share

I ran into this problem a few weeks ago when I used a bargraph to show the progress of 500 operations performed sequentially. I found that the processes were completed long before the bargraph even got halfway. I used the code below:

 bargraph.value = (Target + 1) bargraph.value = (Target) 

Where the bargraph is the name of your object, and the goal is where you want it to move.

Since the bargraph has a graphic aspect, the effect of a tent, it takes time to catch up. Although the graphic side may show a value of 50, the actual value of the bargraph may be 60! By setting the value to a level, and then decreasing it by one, the bargraph instantly (ish) updates the graphic side.

EDIT

As you can see from the comment below, the answer above may not work if you are trying to set the maximum value.

Now, I have not tried this, but I think something in the lines below will work:

 if (bargraph.value <> Target) then if (Target = bargraph.maximumvalue) then bargraph.maximumvalue = Target + 1 bargraph.value = (Target + 1) bargraph.value = (Target) bargraph.maximumvalue = Target else bargraph.value = (Target + 1) bargraph.value = (Target) end if else end if 

As I said, untested, but the principle should work.

+1
source share

All Articles