bonjour,

je me retrouve dans l'impasse malgré les diverses lecture et les divers tests effectué sur cette portion de code

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
 
import java.util.Date;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
 
public class SwtTime {
    public static void main(String[] args){
 
 
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("Time");
        shell.setLayout(new FillLayout(SWT.VERTICAL));
 
        final Label timeLabel = new Label(shell, SWT.CENTER);
 
        Button timeButton = new Button(shell, SWT.PUSH);
        timeButton.setText("Display Time");
        timeButton.addSelectionListener(
                new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        timeLabel.setText(String.format("%tT", new Date()));
                    }
                }
        );
 
        shell.pack();
        shell.open();
        while (!shell.isDisposed()){
            if(!display.readAndDispatch()){
                display.sleep();
            }
        }
        display.close();
    }
}
j'ai le message d'erreur suivant
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
 
Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:4361)
	at org.eclipse.swt.SWT.error(SWT.java:4276)
	at org.eclipse.swt.SWT.error(SWT.java:4247)
	at org.eclipse.swt.widgets.Display.error(Display.java:1064)
	at org.eclipse.swt.widgets.Display.createDisplay(Display.java:821)
	at org.eclipse.swt.widgets.Display.create(Display.java:804)
	at org.eclipse.swt.graphics.Device.<init>(Device.java:130)
	at org.eclipse.swt.widgets.Display.<init>(Display.java:695)
	at org.eclipse.swt.widgets.Display.<init>(Display.java:686)
	at SwtTime.main(SwtTime.java:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
je cherche a faire un simple test affichage avec SWT.
Le problème est que le thread principal est bloqué et je sais pas ou et quoi mettre l'appel de cette méthode
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
display.syncExec(
  new Runnable() {
    public void run(){
     // ????
    }
  });
merci pour votre aide