开发者

How to set attribs in GWT?

开发者 https://www.devze.com 2023-01-04 00:40 出处:网络
I\'m not getting any effect out of DOM.setElementAttribute, am I doing something wrong? class MyListBox extends com.google.gwt.user.client.ui.ListBox {

I'm not getting any effect out of DOM.setElementAttribute, am I doing something wrong?

class MyListBox extends com.google.gwt.user.client.ui.ListBox {
  ....
  protected void setHoverAutoWidth() {
    addDomHandler(new MouseOverHandler() {
      public void onMo开发者_StackOverflow社区useOver(MouseOverEvent event) {
        DOM.setElementAttribute(getElement(), "width", "auto");
      }
    }, MouseOverEvent.getType());
    addDomHandler(new BlurHandler(){
      public void onBlur(BlurEvent event) {
        DOM.setElementAttribute(getElement(), "width", "100px");
      }
    }, BlurEvent.getType());
  }
}

(I know there are less hacky ways to change the width than to set the style attribute directly, but I don't care about css right now.)

Edit: Oops, just realized that width does not change the style width, just adds a width attribute to the tag (which explains why nothing happens). Any suggestions on how to modify the style are still welcome!


I'm pretty sure that will attempt to set the width attribute of the element (which may not exist for the type of element you are working on), NOT the CSS width property.

You're probably looking for setStyleAttribute.


Use DOM.setStyleAttribute


In later versions of GWT you can use getElement().getStyle().setWidth(100, Unit.PX), which gives you a bit of extra compile-time correctness over the String-based methods in the DOM class. Use getElement().getStyle().clearWidth() to set the width back to auto.

0

精彩评论

暂无评论...
验证码 换一张
取 消