Wrap abel in einem zusammengesetzten

Habe ich ScrolledComposite Wonach nur vertikal scrollen. (heighthint = 400).

Innerhalb dieser ScrolledComposite, ich habe ein anderes CompositeA (die Höhe kann mehr als 400 zum "scrollen") zu speichern, alle anderen widgets.

Habe ich ein sehr langes Etikett (mit SWT.WRAP aktiviert). Aber statt Verpackung, es ist immer zeigen, in einer einzigen Zeile. Ich möchte dieses label zu wickeln, nach der Breite des übergeordneten Elements (CompositeA)

Ich vergaß hinzuzufügen, dass dies CompositeA 2 Spalte GridLayout mit makeColumnsEqualWidth = true.

Hier ist mein code:

public void createPartControl(Composite parent) {
    //TODO Auto-generated method stub

    Display display = parent.getDisplay();

    toolkit = new FormToolkit(display);
    form = toolkit.createForm(parent);
    form.setText("ABC");

    Composite body = form.getBody();

    TableWrapLayout layout = new TableWrapLayout();
    layout.numColumns = 2;
    body.setLayout(layout);

    Label header1 = toolkit.createLabel(body, "ABC: ");
    Font font = new Font(display, "Arial", 11, SWT.BOLD);
    header1.setFont(font);

    Label header2 = toolkit.createLabel(body, "XYZ",
            SWT.WRAP);
    font = new Font(display, "Arial", 11, SWT.NONE);
    header2.setFont(font);

    TableWrapData wd = new TableWrapData(TableWrapData.FILL_GRAB);      
    header2.setLayoutData(wd);

    form.getBody().setBackground(
            form.getBody().getDisplay()
                    .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

    //Scrolled composite
    ScrolledComposite sc = new ScrolledComposite(body, SWT.BORDER_SOLID
            | SWT.V_SCROLL);
    sc.setAlwaysShowScrollBars(true);
    sc.setBackground(new Color(display, 50,255,155));


    wd = new TableWrapData(TableWrapData.FILL); 
    wd.heightHint = 360;
    wd.colspan = 2;
    wd.grabHorizontal = false;
    sc.setLayoutData(wd);

    sc.setLayout(new TableWrapLayout());

    Composite innerComposite = toolkit.createComposite(sc);
    sc.setContent(innerComposite);

    innerComposite.setLayout(new TableWrapLayout());
    innerComposite.setBackground(new Color(display, 255,50,50));

    Section section = toolkit.createSection(innerComposite,
            Section.DESCRIPTION | Section.TITLE_BAR | Section.EXPANDED);
    wd = new TableWrapData(TableWrapData.FILL);
    wd.maxWidth = 600; //don't want to hardcode this value

    section.setLayoutData(wd);
    section.setText("Section");
    section.setDescription("A not so long description......................");

    //Composite for Section
    Composite sectionClient = toolkit.createComposite(section);
    layout = new TableWrapLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    sectionClient.setLayout(layout);

    toolkit.createButton(sectionClient, "Button 1", SWT.RADIO);

    Label rightDesc = toolkit
            .createLabel(
                    sectionClient,
                    "A very long long long long long long long long long long long long long long long long long long long long desc that needs wrapping",
                    SWT.WRAP);
    font = new Font(display, "Arial", 10, SWT.ITALIC);
    rightDesc.setFont(font);
    wd = new TableWrapData();
    wd.rowspan = 2;
    rightDesc.setLayoutData(wd);

    Combo comboDropDown = new Combo(sectionClient, SWT.DROP_DOWN
            | SWT.BORDER);
    comboDropDown.setText("DDL");
    comboDropDown.add("1");
    comboDropDown.add("2");
    comboDropDown.add("3");

    Label lineBreak = toolkit.createSeparator(sectionClient, SWT.SEPARATOR
            | SWT.HORIZONTAL);
    wd = new TableWrapData(TableWrapData.FILL);
    wd.colspan = 2;
    lineBreak.setLayoutData(wd);

    /***********************/

    toolkit.createButton(sectionClient, "Button 2", SWT.RADIO);

    Label rightDesc2 = toolkit
            .createLabel(
                    sectionClient,
                    "A long long long long long long long long long long long long long long long long long long long long desc that needs wrapping",
                    SWT.WRAP);
    font = new Font(display, "Arial", 10, SWT.ITALIC);
    rightDesc2.setFont(font);
    wd = new TableWrapData(TableWrapData.FILL);
    wd.rowspan = 3;
    rightDesc2.setLayoutData(wd);

    toolkit.createLabel(sectionClient, "Desc",
            SWT.WRAP);
    toolkit.createText(sectionClient, "hello world", SWT.NONE);

    section.setClient(sectionClient);

    innerComposite.pack();

}

Wenn Sie Sie ausführen, sehen Sie eine grüne scrolledcomposite und einem roten composite. Ich will den roten composite-Breite zu füllen, um die Breite des scrolledcomposite relativ ohne hardcoding maxWidth = 600.

  • Ich glaube, ich hatte ein ähnliches Problem, und ich löste es mit FILL für horizontalAlignment und true für grabExcessHorizontalSpace im GridData des Labels und der Verbund, die es. Hoffe, das hilft.
  • ich denke, wenn ich rufe innerComposite.pack() es wird das layout der Beschriftung in eine einzelne Zeile? Aber ohne innerComposite.pack() ich nicht in der Lage, um zu sehen, das gesamte layout.
InformationsquelleAutor humansg | 2012-08-02
Schreibe einen Kommentar