Reputation: 41
I Have problem with application that invoke splash screen with progrss bar during initialization, this is part of code inside my app,
try {
Runtime runTime = Runtime.getRuntime();
pbaw = runTime.exec(cmdGen);
//pbaw = probuilder.start();
try {
String line;
BufferedReader input =
new BufferedReader(new InputStreamReader(pbaw.getInputStream()));
SplashScreen ss= new SplashScreen(Display.getCurrent(), getShell());
int progress = 0;
ss.show();
while ((line = input.readLine()) != null) {
ss.setLabel(line);
progress+=1;
ss.advance(progress);
//System.out.println(line); //<-- Parse data here.
}
input.close();
ss.destroy(pbaw.waitFor());
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
my question is why the progrss bar in splash screen can not update while i click in desktop or running other application, but my applicatin can run perfectly, please help ??? here part of my splash scrren code to make it clear,
void advance(final int progress) {
if (!progressBar.isDisposed()) {
progressBar.setSelection(progress);//progressBar.getSelection() + progress);
progressBar.redraw();
}
}
public void show() {
mainShell.pack();
mainShell.open();
}
void destroy(int val) {
if (val==0){
splashComposite.dispose();
if (appImage != null) {
appImage.dispose();
}
mainShell.dispose();
}
}
Upvotes: 0
Views: 210
Reputation: 111216
You are running your code in the User Interface thread and never giving SWT a chance to update. You need to run your reading code in a separate thread and use Display.asyncExec
to update the splash screen in the UI thread.
Upvotes: 1