GridLayout SWT: Anordnung Composites nebeneinander

StarSheriff

Mitglied
Hallo,

ich habe ein Frage zum GridLayout im SWT.
Folgender Code bricht meine Frage aufs wesentliche runter:
Java:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class SwtLayoutExample
{
    public static void main(String[] args)
    {
        Display display = new Display();
        Shell shell = new SwtLayoutExample().createShell(display);
        shell.open();
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }

    private Shell createShell(Display display)
    {
        final Shell shell = new Shell(display);
        shell.setText("GridLayout");
        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 1;
        shell.setLayout(gridLayout);

        Composite parent = new Composite(shell, SWT.NONE);
        GridLayout gl = new GridLayout(2, true);
        parent.setLayout(gl);

        Composite child1 = new Composite(parent, SWT.NONE);
        GridLayout gl1 = new GridLayout(2, true);
        child1.setLayout(gl1);

        new Label(child1, SWT.NONE).setText("LinkeSeite");
        new Label(child1, SWT.NONE).setText("RechteSeite");
        new Label(child1, SWT.NONE).setText("zweiteZeile");

        Composite child2 = new Composite(parent, SWT.NONE);
        GridLayout gl2 = new GridLayout(3, true);
        child2.setLayout(gl2);
        Label l1 = new Label(child2, SWT.NONE);
        l1.setText("Links");
        GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER, SWT.BEGINNING, false, true);
        l1.setLayoutData(data);
        new Label(child2, SWT.NONE).setText("Mitte");
        new Label(child2, SWT.NONE).setText("Rechts");
      
//        new Label(child2, SWT.NONE).setText("zweite Zeile links");
        return shell;
    }
}

Wie schaffe ich es, dass im rechten Child-Composite die Elemente auf Höhe der ersten Zeile des linken child-Composite sind. (sobald ich die Zeile
Java:
//        new Label(child2, SWT.NONE).setText("zweite Zeile links");
einkommentiere ist das der Fall, ich habe aber in meine Programm eben unterschiedliche Anzahl von Reihen im linken und rechten Composite.
verticalSpan hab ich schon versucht, hat nix gebracht.

Danke vorab
StarSheriff
 
Probier mal auf dem "link" Label einen GridData zuzuweisen. Ist schließlich eine Zellenfromatierung.

Java:
package net.enbw.rdp.server.presentation;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class SwtLayoutExample
{
     public static void main(String[] args)
     {
         Display display = new Display();
         Shell shell = new SwtLayoutExample().createShell(display);
         shell.open();
         while (!shell.isDisposed())
         {
             if (!display.readAndDispatch())
                 display.sleep();
         }
     }

     private Shell createShell(Display display)
     {
         final Shell shell = new Shell(display);
         shell.setText("GridLayout");
         GridLayout gridLayout = new GridLayout();
         gridLayout.numColumns = 1;
         shell.setLayout(gridLayout);

         Composite parent = new Composite(shell, SWT.NONE);
         GridLayout gl = new GridLayout(2, true);
         parent.setLayout(gl);

         Composite child1 = new Composite(parent, SWT.NONE);
         GridLayout gl1 = new GridLayout(2, true);
         child1.setLayout(gl1);

         new Label(child1, SWT.NONE).setText("LinkeSeite");
         new Label(child1, SWT.NONE).setText("RechteSeite");
         new Label(child1, SWT.NONE).setText("zweiteZeile");
         new Label(child1, SWT.NONE);

         Composite child2 = new Composite(parent, SWT.NONE);
         child2.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
         GridLayout gl2 = new GridLayout(3, true);
         child2.setLayout(gl2);
         Label linksLabel = new Label(child2, SWT.NONE);
         linksLabel.setText("Links");
         linksLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER, GridData.VERTICAL_ALIGN_BEGINNING, true, true));
         new Label(child2, SWT.NONE).setText("Mitte");
         new Label(child2, SWT.NONE).setText("Rechts");
      
//        new Label(child2, SWT.NONE).setText("zweite Zeile links");
         return shell;
     }
}
 

Neue Themen


Zurück
Oben