SWT - Dialog

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

SWT - Dialog

Postby matthias333 » Tue May 31, 2005 11:27 am

The generated code from a dialog needs a shell which is called parent and i want to open the dialog from a main-shell.
is the parent shell from the dialog the shell from the main?
here is my code
Code: Select all
public class GUIMain extends Shell {
   public static void main(String args[]) {
      try {
         Display display = Display.getDefault();
         GUIMain shell = new GUIMain(display, SWT.SHELL_TRIM);
         while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
      } catch (Exception e) {

   public GUIMain(Display display, int style) {
      super(display, style);

   protected void createContents() {
      setText("SWT Application");
      setSize(500, 375);
      setLayout(new RowLayout());

      final Button button = new Button(this, SWT.NONE);
      button.addSelectionListener(new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
            GUIPersonPicker pp = new GUIPersonPicker(getParent().getShell());

   protected void checkSubclass() {


Code: Select all
public class GUIPersonPicker extends Dialog {

   private Table table_1;
   private Text text_1;
   protected Object result;

   protected Shell shell;

   public GUIPersonPicker(Shell parent, int style) {
      super(parent, style);

   public GUIPersonPicker(Shell parent) {
      this(parent, SWT.NONE);

   public Object open() {
      Display display = getParent().getDisplay();
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch())
      return result;

   protected void createContents() {
      shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
      shell.setLayout(new GridLayout());
      shell.setSize(470, 603);
      shell.setText("SWT Dialog");

      final Label label = new Label(shell, SWT.NONE);
      label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
      label.setText("Suchen nach:");

      text_1 = new Text(shell, SWT.BORDER);
      text_1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

      final Label label_1 = new Label(shell, SWT.NONE);
      label_1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

      table_1 = new Table(shell, SWT.FULL_SELECTION | SWT.BORDER);
      final GridData gridData_2 = new GridData(GridData.FILL_BOTH);
      gridData_2.horizontalSpan = 2;

      final TableColumn firstname = new TableColumn(table_1, SWT.NONE);

      final TableColumn surname = new TableColumn(table_1, SWT.NONE);

      final TableColumn place = new TableColumn(table_1, SWT.NONE);
      place.setText("PLZ - Ort");

      final TableColumn street = new TableColumn(table_1, SWT.NONE);
      street.setText("Straße - Nr.");

      final TableColumn tableColumn = new TableColumn(table_1, SWT.NONE);
      tableColumn.setText("New column");


when i use the button the whole application shuts - what is wrong?
Posts: 1
Joined: Tue May 31, 2005 11:19 am

Postby Slot Head » Mon Jul 18, 2005 4:26 pm

Instead of:
Code: Select all

I suggest you try:
Code: Select all
Slot Head
Posts: 36
Joined: Sun Jul 10, 2005 9:50 am

Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest