简体   繁体   中英

Create a Composite that adapt to my data in Eclipse SWT

My First try is:

public MultiLangugeText(Composite parent, int style) {
    super(parent, style);
    setLayout(new RowLayout(SWT.HORIZONTAL));

    Map<Locale, String> texts = new HashMap<Locale, String>();
    texts.put(Locale.GERMAN, "Hey du");
    texts.put(Locale.ENGLISH, "Hey you");
    texts.put(Locale.FRENCH, "Bon Jour");
    setTexts(texts);

public void setTexts(Map<Locale, String> texts) {
    for (Locale locale : texts.keySet()) {
        createTextComposite(locale, texts.get(locale));
    }
}

private void createTextComposite(Locale locle, String localizedString) {
    Composite composite = formToolkit.createComposite(this, SWT.BORDER);
    formToolkit.paintBordersFor(composite);
    composite.setLayout(new RowLayout(SWT.HORIZONTAL));

    CLabel label = new CLabel(composite, SWT.NONE);
    label.setText(locle.toString());
    formToolkit.adapt(label);
    formToolkit.paintBordersFor(label);

    Text txtString = new Text(composite, SWT.BORDER);
    txtString.setText(localizedString);
    formToolkit.adapt(txtString, true, true);
}

But this code will not draw anything on my UI. At least when I try to render it in the Deisigner and in the Preview. I have to tests if this works, when I use it in my application. But I don't get where error is.

好的,它只会在设计器中失败,而在您实际使用复合材料elsewehre时不会失败。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM