将abel包装在复合材料中 [英] Wrap abel within a composite

查看:133
本文介绍了将abel包装在复合材料中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ScrolledComposite ,它仅允许垂直滚动。 ( heighthint = 400 )。

I have ScrolledComposite which allows only vertical scrolling. (heighthint = 400).

在此ScrolledComposite中,我还有一个 CompositeA (滚动时高度可能超过400)来存储所有其他小部件。

Within this ScrolledComposite, I have another CompositeA (height may exceed 400 for scrolling) to store all other widgets.

我的标签很长(带有 SWT。启用WRAP )。但是,与其包装,它始终显示在一行中。我希望此标签根据其父标签的宽度( CompositeA

I have a very long label (with SWT.WRAP enabled). But instead of wrapping, it is always showing in a single line. I want this label to wrap according to the width of its parent (CompositeA)

我忘了补充一下 CompositeA 是2列 GridLayout ,其中 makeColumnsEqualWidth = true

I forgot to add that this CompositeA is a 2 column GridLayout with makeColumnsEqualWidth = true.

这是我的代码:

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();

}

如果运行它,您会看到绿色的滚动复合图像,红色的复合材料。我希望红色合成宽度相对地填充到scrolledcomposite的宽度,而无需硬编码 maxWidth = 600

If you run it, you can see a green scrolledcomposite and a red composite. I want the red composite width to fill to the width of the scrolledcomposite relatively without hardcoding maxWidth = 600.

推荐答案

我在布局中遇到了同样的问题,发现有用的答案。

I have the same problem here in my layout and found this useful answer.

由于这不是错误,它是一个功能,请尝试从注释#19尝试该答案< a href = https://bugs.eclipse.org/bugs/show_bug.cgi?id=9866 rel = noreferrer>此处。

Because of 'it is a not bug, it is a feature' try this answer from comment #19 here.

我为标签使用了以下代码行。

I use the following lines of code for my Label.

Label tip = new Label(shell, SWT.WRAP | SWT.BORDER | SWT.LEFT);
final GridData data = new GridData(SWT.HORIZONTAL, SWT.TOP, true, false, 1, 1);
tip.setLayoutData(data);
tip.setText("Here stands my long, long and much more longer text...");

这篇关于将abel包装在复合材料中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆