GWT TextButton class - How to set an icon?

792 views
Skip to first unread message

tom

unread,
Sep 16, 2011, 8:59:04 AM9/16/11
to google-we...@googlegroups.com
Hi,

I'd like to have Buttons with a text and an icon in my app. Seems the TextButton class is exactly what I'm looking for.

The only way to set the icon seems to be the constructor that takes a TextButtonCell, but it is protected. Can't use that. :( Bug or feature??

How can I set the icon for a TextButton in a short, elegant way?

regards

Tom

Tony Jewell

unread,
Nov 12, 2011, 5:19:54 AM11/12/11
to Google Web Toolkit
You've probably solved this yourself, but here's what I did:

IResources.java:
==============8<===============
package com.cregganna.web.gwt.ui.resources;

import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;

public interface IResources extends ClientBundle {
@Source("selectAll_16x16.gif")
ImageResource selectAllIcon();
...
}
==============8<===============

In the ui.xml:
==============8<===============
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder
xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:cc='urn:import:com.cregganna.web.gwt.ui'
>

<ui:with field='res'
type='com.cregganna.web.gwt.ui.resources.IResources' />
<ui:with field='msg'
type='com.cregganna.web.gwt.ui.resources.IMessageConstants' />
....

<cc:widgets.IconTextButton icon='{res.selectAllIcon}'
text='{msg.selectAll}' width='100px' ui:field='selectAll' />
==============8<===============


IconTextButton.java:
==============8<===============
package com.cregganna.web.gwt.ui.widgets;

import com.google.gwt.cell.client.TextButtonCell;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.widget.client.TextButton;

public class IconTextButton extends TextButton {

public void setIcon(ImageResource icon) {
((TextButtonCell) getCell()).setIcon(icon);
}

}
==============8<===============

On Sep 16, 12:59 pm, tom <majortom...@gmail.com> wrote:
> Hi,
>
> I'd like to have Buttons with a text and an icon in my app. Seems the
> TextButton<http://google-web-toolkit.googlecode.com/svn/javadoc/2.4/com/google/g...>class is exactly what I'm looking for.
Reply all
Reply to author
Forward
0 new messages