Dies ist eine alte Version des Dokuments!


Dialog (JFace)

org.eclipse.jface.dialogs.Dialog



Das Beispiel zeigt einen einfachen Dialog mit einem Titel, welcher ein Label und ein Text-Feld enthält:

public class MyDialog extends Dialog {
   private Label label;
   private Text text;
 
   protected MyDialog(Shell parentShell) {
      super(parentShell);
   }
 
   @Override
   protected void configureShell(Shell shell) {
      super.configureShell(shell);
      shell.setText("MyTitle");  // Dialog-Titel setzen
   }
 
   @Override
   protected Control createDialogArea(Composite parent) {
      Composite composite = (Composite) super.createDialogArea(parent);
 
      composite.setLayout(new GridLayout(1, false));
 
      label = new Label(composite, SWT.FLAT);
      GridData gdl = new GridData();
      gdl.grabExcessHorizontalSpace = true;
      label.setLayoutData(gdl);
      label.setText("Ihre Eingabe: ");
 
      text = new Text(composite, SWT.FLAT|SWT.BORDER);
      GridData gdt = new GridData();
      gdt.grabExcessHorizontalSpace = true;
      text.setLayoutData(gdt);
 
      return composite;
   }
 
   @Override
   public void okPressed() {
      String str = text.getText();
 
      System.out.println(str);
      close();
   }
}


Aufruf des Dialogs:

MyDialog dialog = new MyDialog(Display.getCurrent().getShell());
if (dialog.open() == Window.OK) {
   // mach irgendwas
}

Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007