Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Progressbar display sync
Progressbar display sync [message #1710881] Sat, 10 October 2015 08:30
Peter Vaclavek is currently offline Peter VaclavekFriend
Messages: 3
Registered: October 2015
Junior Member
Hi all!

I'm having a problem with continuous refreshing of progress bar (increment a progress bar until is full and do it in loop).
My goal is to fill my progress bar smoothly (in aprox. 5sec from 0 to max) and repeat this in a loop.

Here is snippet of my code, it's working but when progress is about 80% it will be suddenly reset to 0 (which is OK, but it should be done on 100%).
I don't understand this behavior. Even if I use the syncExec (thanks to which it should execute all the UI runnables until it continues further), the UI runnables were executed but UI was not updated (at least not in realtime but with delay)... it looks like every update of progress bar status is delayed on UI and when the main thread resets the progress bar back to 0 the UI is not displaying the actual state (which is really 100% in non UI thread) but it is only on 80% (because of some sort of paint delay).

How should be fixed? What is wrong with this code?

public class Test {

	private static boolean full = false;

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setSize(200, 100);;

		ProgressBar bar = new ProgressBar(shell, SWT.SMOOTH);
		bar.setBounds(30, 10, 100, 30);

		new Thread(new Runnable() {

			public void run() {

				// For ever and ever...
				while (true) {
					// Update UI & set progress bar to 0
					Display.getDefault().asyncExec(new Runnable() {

						public void run() {
							// Some additional UI updates ...

							full = false;

					// Until progress bar isn't full...
					while (!full) {

						// Sleep
						try {
						} catch (InterruptedException e) {

						// Increment progress bar
						Display.getDefault().syncExec(new Runnable() {
							public void run() {
								if (bar.getSelection() >= bar.getMaximum()) {
									full = true;

								bar.setSelection(bar.getSelection() + 1);


		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())

[Updated on: Mon, 12 October 2015 19:58]

Report message to a moderator

Previous Topic:font display issues with mars/centos6
Next Topic:Shortcut key for combobox?
Goto Forum:

Current Time: Fri Jan 22 04:27:36 GMT 2021

Powered by FUDForum. Page generated in 0.01982 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top