1

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. 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. How can i display that fonts list in "combo box" with "cell table" .

4

1 回答 1

0

Cells in GWT can have custom renderer. 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);
    }
}
于 2013-06-10T00:56:16.803 回答