tags:

views:

91

answers:

2

hi, all

I need to create a pushButton(so it's a button with image) in gwt with UiBinder but not sure how, here is my ui.xml code:

...
<g:PushButton ui:field="myPushButton"/>
...

and in *.java file i defined: PushButton myPushButton;

how can i add an image to the push button? i tried the following but wont' work:

<g:PushButton ui:field="myPushButton" image="myImage.gif"/>

thanks

A: 

You can use following code straight from CustomButton Javadoc:

g:PushButton ui:field='pushButton' enabled='true'>
   <g:upFace>
     <b>click me</b>
   </gwt:upFace>
   <g:upHoveringFace>
     <b>Click ME!</b>
   </gwt:upHoveringFace>

   <g:downFace image='{downButton}'/>
   <g:downHoveringFace image='{downButton}'/>
 </g:PushButton>

There's more in JavaDoc: http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/client/ui/CustomButton.html

Xo4yHaMope
A: 

then one more question: how can i defined the image resource for the button?

here is what i tried:

in the ui.xml file:

..
<ui:image field="upCal" src="../resources/button_cal.gif"></ui:image>
..
<g:PushButton ui:field="myPushButton" image="{upCal}"/>

also in .java code, i defined:(do i need this one?)

Image upCal;

then it complained no such image file can be found. i checked it again and again, the image file was there, is that true gwt have a default directory for the image resources? what's that default directory then? i have my direcotry as:

  src/main/java(where my java and ui.xml file are)
  src/main/resources(where my images locate at /com/company/service/public/img)

what's wrong with my code? thanks.

ohana
Try change image src to this: src="../resources/com/company/service/public/img/button_cal.gif"
Xo4yHaMope