The following works for me:

/** An HTML anchor that can wrap an arbitrary widget (for example, a GWT
 *    Image object).
 *
 *  (c) 2009 Allen I Holub.
 */
public class WidgetAnchor extends HTMLPanel
{
    public WidgetAnchor( String href, Widget contents )
    {    this( href, "", contents );
    }

public WidgetAnchor( String href, String otherAttributes, Widget contents )
    {
super( "<a href='" + href + "' " + otherAttributes + "><div id='contents'></div></a>" );
        addAndReplaceElement( contents, "contents" );
    }
}

Just pass the constructor a GWT Imageobject. (Bear in mind, by the way, that the GWT Image is a proxy for the actual image element on the page, which is to say that you can't display the same Image object twice on the same page. You need to instantiate two Imageobjects with the same underlying file to do that).

-Allen Holub



On 1/15/11 2:25 PM, zixzigma wrote:
g:InlineHyperLink, g:HyperLink and g:Anchor cannot contain an element
if I'm correct.

do you know how we can then wrap an image inside a hyperlink,
other than the approach below?


<g:HTMLPanel>
<a href="#mail/starred">
                         Home
                         <g:Image resource="{res.homeIcon}" />
</a>
</g:HTMLPanel>


--
You received this message because you are subscribed to the Google Groups "Google 
Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to