How to add an icon to MenuItem?

385 views
Skip to first unread message

membersound

unread,
May 6, 2013, 9:38:38 AM5/6/13
to google-we...@googlegroups.com
Hi,

how can I get add an icon with text to a menu item in GWT? The following does not work:

<ui:with field='res' type='my.package.MyResources' />

<gwt:MenuBar>
<g:MenuItem text="test"><g:Image resource="{res.myIcon}" /></g:MenuItem>


Resulting error:
Not allowed in an HTML context: <g:Image resource='{res.myIcon}'>

So how can I have an icon in menuitem?

Honza Rames

unread,
May 13, 2013, 5:58:00 AM5/13/13
to google-we...@googlegroups.com
Hi,
I came across the same problem, I had to create a subclass of MenuItem which sets MenuItem's setHTML and gives it a built up image + text HTML string. I used ClippedImageImpl to create the image HTML.

Andrea Boscolo

unread,
May 13, 2013, 7:15:28 AM5/13/13
to google-we...@googlegroups.com

Honza Rames

unread,
May 13, 2013, 11:00:37 AM5/13/13
to google-we...@googlegroups.com
Yep, this is a nice way to do this as well but if you want to use UiBinder with <ui:with ... /> having the MenuItem subclassed is much more convenient because then I can set ImageResource directly from the ClientBundle.
Reply all
Reply to author
Forward
0 new messages