简体   繁体   English

GWT:如何更改GWT Celltable中的行字体?

[英]GWT:how to change row font in GWT Celltable?

I have list of fonts in Array List, i am adding this fonts into cell table (GWT), but complete list is displaying default font only. 我在“数组列表”中有字体列表,我正在将该字体添加到单元格表(GWT)中,但是完整列表仅显示默认字体。 But my requirement is if font name is "Arial" that name should be displayed with "Arial" font and if font name is "Calibri" that name should be displayed with "Calibri" font, like that remaining fonts also. 但是我的要求是,如果字体名称为“ Arial”,则该名称应显示为“ Arial”字体;如果字体名称为“ Calibri”,则该名称应显示为“ Calibri”字体,其余字体也应如此。 How can i display that fonts list in "combo box" with "cell table" . 如何在“组合框”和“单元格表”中显示字体列表。

Cells in GWT can have custom renderer. GWT中的单元可以具有自定义渲染器。 Please refer to this sample for details - I tried to keep it as simple as possible: 请参考此示例以获取详细信息-我试图使其尽可能简单:

public class Sample implements EntryPoint {

    private static final Templates T = GWT.create(Templates.class);

    public interface Templates extends SafeHtmlTemplates {
        @Template("<span style='{0}'>{1}</span>")
        SafeHtml fontName(SafeStyles styles, String name);
    }

    static class Font {
        String name;
        public Font(String name) {
            this.name = name;
        }
    }

    class FontCell extends AbstractCell<Font> implements Cell<Font> {
        @Override
        public void render(Context context, Font font, SafeHtmlBuilder sb) {
            sb.append(T.fontName(SafeStylesUtils.fromTrustedNameAndValue("font-family", font.name), font.name));
        }
    }

    class FontColumn extends Column<Font, Font> {
        public FontColumn() {
            super(new FontCell());
        }

        @Override
        public Font getValue(Font object) {
            return object;
        }
    }

    private static List<Font> fonts = Arrays.asList(
            new Font("Arial"),
            new Font("Courier New"),
            new Font("Tahoma"),
            new Font("Verdana"));

    public void onModuleLoad() {
        CellTable<Font> cellTable = new CellTable<Font>();
        cellTable.addColumn(new FontColumn(), "Font");
        new ListDataProvider<Font>(fonts).addDataDisplay(cellTable);
        RootPanel.get().add(cellTable);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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