Bonjour à toutes et à tous,
Je ne suis pas très à l’aise avec SWT c'est pour cela que je vous demande votre aide.
Mon interface graphique est simple voici mon code:
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
|
final Display display = new Display ();
final Shell shell = new Shell (display);
shell.setText ("Interface");
GridLayout gridLayout = new GridLayout (4, false);
gridLayout.verticalSpacing = 8;
shell.setLayout (gridLayout);
Button source = new Button (shell, SWT.NULL);
source.setText ("Source...");
GridData gridData = new GridData ();
gridData.horizontalSpan = 1;
gridData.verticalSpan = 2;
gridData.heightHint = 50;
gridData.widthHint = 100;
source.setLayoutData (gridData);
Label sourceLabel = new Label (shell, SWT.NULL);
sourceLabel.setText ("Dossier source : ");
gridData = new GridData (GridData.HORIZONTAL_ALIGN_FILL);
sourceLabel.setLayoutData (gridData);
final Label sourceResLabel = new Label (shell, SWT.NULL);
sourceResLabel.setText (directoryToScan);
gridData = new GridData (GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 2;
sourceResLabel.setLayoutData (gridData);
source.addSelectionListener (new SelectionAdapter ()
{
public void widgetSelected (SelectionEvent e)
{
DirectoryDialog dialog = new DirectoryDialog (shell, SWT.OPEN);
String file = dialog.open ();
if (file != null)
{
sourceResLabel.setText (file);
directoryToScan = file;
}
}
});
Label destLabel = new Label (shell, SWT.NULL);
destLabel.setText ("Dossier destination : ");
gridData = new GridData (GridData.HORIZONTAL_ALIGN_FILL);
destLabel.setLayoutData (gridData);
Label destResLabel = new Label (shell, SWT.NULL);
destResLabel.setText (directoryToParse);
gridData = new GridData (GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 2;
destResLabel.setLayoutData (gridData);
final Button generate = new Button (shell, SWT.PUSH);
generate.setText ("Générer");
gridData = new GridData ();
gridData.heightHint = 30;
gridData.widthHint = 100;
gridData.horizontalSpan = 3;
gridData.horizontalAlignment = GridData.CENTER;
generate.setLayoutData (gridData);
generate.addSelectionListener (new SelectionAdapter ()
{
public void widgetSelected (SelectionEvent e)
{
generate ();
generate.setEnabled (true);
}
});
log = new Text (shell, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.READ_ONLY);
gridData = new GridData (GridData.HORIZONTAL_ALIGN_FILL
| GridData.VERTICAL_ALIGN_FILL);
gridData.horizontalSpan = 4;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
log.setLayoutData (gridData);
shell.setSize (450, 400);
shell.open ();
while (!shell.isDisposed ())
{
if (!display.readAndDispatch ())
{
display.sleep ();
}
}
display.dispose (); |
Ce code est censé me générer la vue en pièce jointe (illustration.png).
Cependant, j'obtient la vue illustrée par la deuxième pièce jointe (illustration2.png).
Deux remarques:
_ Mes éléments ne prennent pas l'ensemble de ma fenêtre
_ Les deux libellés indiquant des chemins sont tronqués alors qu'il reste beaucoup de place sur la droite.
Je n'arrive pas à corriger ces deux bogues. Auriez vous une solution?
Deuxième chose, lorsque j'appuie sur générer, ceci execute un programme assez long ce qui fait que ma fenêtre est bloqué (ne répond pas). La solution est de mettre un Thread mais ceci ne fonctionne pas bien.
Le plus génant est que j'aimerai afficher des chose dans mon Log au fur et à mesure que mon programme s'execute donc j'ecris:
1 2 3
|
log.setText ("Log...");
log.setText (log.getText () + "Traitement des fichiers..."); |
Cependant, rien ne s'affiche même avec le thread! Seriez vous pourquoi? Peut être que si le programme est trop chargé il n'arrive pas à gérer!
Merci d'avance pour votre aide précieuse
Partager