Bonjour,

J'aimerais savoir pourquoi ma progressBar dont j'augmente la valeur à partir d'un Thread ne va pas jusqu'au bout graphiquement alors qu'au niveau du code la valeur maximale est atteinte.
Voilà ce que ca donne :
Nom : progressbar_dvp.png
Affichages : 174
Taille : 22,9 Ko

Du coup elle se ferme toujours avant que la jauge ait été jusqu'au bout...

Voici le code de la boite de dialogue contenant la progressBar :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
public class LoadingDialog extends Dialog implements Observer, SelectionListener {
 
	private static final Logger log = LogManager.getLogger(LoadingDialog.class.getName());
 
	private Composite container;
 
	private Label labelInfo;
 
	private final HelloSWTJFace mainApplication;
 
	private ProgressBar progressBar;
 
	private ProjectsLoader projectsLoader;
 
	public LoadingDialog(HelloSWTJFace mainApplication) {
 
		super(mainApplication);
 
		this.mainApplication = mainApplication;
 
	}
 
	@Override
	protected void configureShell(Shell shell) {
 
		super.configureShell(shell);
 
		shell.setText(HelloSWTJFace.props.getProperty("messageDialogTitle.Loading"));
	}
 
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
 
		final Button button = this.createButton(parent, IDialogConstants.CANCEL_ID,
				HelloSWTJFace.props.getProperty("button.Cancel"), true);
		button.addSelectionListener(this);
	}
 
	@Override
	protected Control createDialogArea(Composite parent) {
 
		this.container = (Composite) super.createDialogArea(parent);
		final GridLayout gridLayout = new GridLayout(1, true);
		gridLayout.marginRight = 7;
		gridLayout.marginLeft = 10;
		gridLayout.marginTop = 10;
		gridLayout.marginBottom = 10;
		this.getContainer().setLayout(gridLayout);
		this.getContainer().setLayoutData(new GridData(325, 100));
		this.progressBar = new ProgressBar(this.getContainer(), SWT.HORIZONTAL | SWT.SMOOTH);
		final GridData gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		gridData.horizontalSpan = 1;
		gridData.heightHint = 50;
		this.getProgressBar().setLayoutData(gridData);
		this.getProgressBar().setMinimum(0);
		this.getProgressBar().setMaximum(100);
		this.labelInfo = new Label(this.getContainer(), SWT.NONE);
 
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		gridData.horizontalSpan = 1;
		gridData.heightHint = 50;
		this.getLabelInfo().setLayoutData(gridData);
 
		return this.container;
	}
 
	public Composite getContainer() {
 
		return this.container;
	}
 
	@Override
	protected Point getInitialSize() {
 
		return super.getInitialSize();
	}
 
	public Label getLabelInfo() {
 
		return this.labelInfo;
	}
 
	public HelloSWTJFace getMainApplication() {
 
		return this.mainApplication;
	}
 
	public ProgressBar getProgressBar() {
 
		return this.progressBar;
	}
 
	public ProjectsLoader getProjectsLoader() {
 
		return this.projectsLoader;
	}
 
	public void setProjectsLoader(ProjectsLoader projectsLoader) {
 
		this.projectsLoader = projectsLoader;
	}
 
	@Override
	public void update(Observable arg0, Object arg1) {
 
		// log.warn("updateObservable : " + arg0);
 
		if (arg0 instanceof ProjectsLoader) {
 
			this.setProjectsLoader((ProjectsLoader) arg0);
 
			// log.warn("projectsLoader : " + this.getProjectsLoader());
 
			try {
 
				this.getProgressBar().getDisplay().asyncExec(new Runnable() {
 
					@Override
					public void run() {
 
						LoadingDialog.this.progressBar.setSelection(LoadingDialog.this.progressBar.getSelection() + 1);
 
						if (LoadingDialog.this.progressBar
								.getSelection() < (LoadingDialog.this.progressBar.getMaximum())) {
 
							LoadingDialog.this.labelInfo.setText(
									String.valueOf(LoadingDialog.this.progressBar.getSelection() + 1) + " / 100");
						}
						else if (LoadingDialog.this.progressBar
								.getSelection() == (LoadingDialog.this.progressBar.getMaximum())) {
 
							try {
 
								Thread.sleep(2000);
 
							}
							catch (final Exception e) {
 
								log.warn(e.fillInStackTrace());
							}
 
							LoadingDialog.this.close();
						}
					}
				});
			}
			catch (final Exception e) {
 
				log.warn("Interrupted : " + e.fillInStackTrace());
			}
		}
	}
 
	@Override
	public void widgetDefaultSelected(SelectionEvent arg0) {
 
	}
 
	@Override
	public void widgetSelected(SelectionEvent arg0) {
 
		log.warn("widgetSelected : " + arg0.getSource());
 
		try {
 
			this.getProjectsLoader().stop();
 
		}
		catch (final NullPointerException e) {
 
			log.warn(e.fillInStackTrace());
		}
 
	}
}
Une entité bidon qui me sert juste de base :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package org.helloswtjface.entities;
 
import java.util.Observable;
import java.util.Observer;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.helloswtjface.dialogs.LoadingDialog;
import org.helloswtjface.threads.LoadingThread;
 
public class ProjectsLoader extends Observable {
 
	private static final Logger log = LogManager.getLogger(ProjectsLoader.class.getName());
 
	private boolean loading;
 
	private final LoadingDialog loadingDialog;
 
	public ProjectsLoader(LoadingDialog loadingDialog) {
 
		this.loading = false;
		this.loadingDialog = loadingDialog;
		this.addObserver(loadingDialog);
		this.start();
 
	}
 
	@Override
	public void addObserver(final Observer observer) {
 
		log.warn("addObserver : " + observer);
 
		super.addObserver(observer);
	}
 
	public LoadingDialog getLoadingDialog() {
 
		return this.loadingDialog;
	}
 
	public boolean isLoading() {
 
		return this.loading;
	}
 
	public void setLoading(boolean loading) {
 
		this.loading = loading;
	}
 
	public void start() {
 
		this.setLoading(true);
 
		if (this.isLoading()) {
 
			final LoadingThread loadingThread = new LoadingThread(this);
 
			loadingThread.start();
		}
 
	}
 
	public void stop() {
 
		this.setLoading(false);
	}
 
	public void update() {
 
		this.setChanged();
		this.notifyObservers();
	}
}
et enfin le Thread :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.helloswtjface.threads;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.helloswtjface.entities.ProjectsLoader;
 
public class LoadingThread extends Thread {
 
	private static final Logger log = LogManager.getLogger(LoadingThread.class.getName());
 
	private final ProjectsLoader projectsLoader;
 
	public LoadingThread(ProjectsLoader projectsLoader) {
 
		super();
 
		this.projectsLoader = projectsLoader;
 
	}
 
	public ProjectsLoader getProjectsLoader() {
 
		return this.projectsLoader;
	}
 
	@Override
	public void run() {
 
		int i = 0;
 
		while ((i < 100) && this.getProjectsLoader().isLoading()) {
 
			try {
 
				Thread.sleep(100);
 
				i++;
 
				log.warn("ProgressBar : " + i + "%");
 
				this.getProjectsLoader().update();
			}
			catch (final InterruptedException e) {
 
				i = 100;
 
				this.getProjectsLoader().stop();
 
				log.warn("LoadingThread : " + e.fillInStackTrace());
			}
		}
 
		this.getProjectsLoader().stop();
	}
}
Je précise que je débute...
Merci d'avance.