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. 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" .

Answers


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

Need Your Help

unable to bind the data

c# .net silverlight listbox windows-phone

I created a WCF service. I am trying to implement the interface at my app end.

BlackBerry Push Notifications , OS < 7.X

blackberry push-notification push

I am working on developing a BB OS&lt;7.X application, that implements push notifications. I finally ended up with some working code that is able to receive push.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.