Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Updating styles runtime

    I have a label with lbl.setStyleName("somestyle"), and later on when that label becomes clickable I want to change the style to lbl.setStyleName("someotherstyle"), but I can't seem to do this seemingly simple task.

    Here's what I've tried:

    Code:
    lbl.setStyleName("styledFont");
    ...
    ... (code)
    ...
    Code:
    lbl.setStyleName("styledFontClickable");
    Window.alert(lbl.getStyleName());
    lbl.markForRedraw();
    The Window.alert presents the correctly changed style, but nothing happens at all on the page itself. That is, the style doesn't change. It's unfortunate.

    Any help would be greatly appreciated

    Thanks

    #2
    Code looks fine, possibly your CSS is incorrect. You can check with Firebug that the new style has been applied to the element.

    Comment


      #3
      Hi,

      it was not my thread, but I have exactly the same problem, so I use this one. Hope, thats ok.

      this is my example:

      Code:
      private count;
      public void onModuleLoad() {
      		HLayout panel = new HLayout(20);
      		count = 0;
      		panel.setWidth100();
      		panel.setHeight100();
      		final com.smartgwt.client.widgets.Label label = new com.smartgwt.client.widgets.Label();
      		label.setContents("TEST");
      		label.setStyleName("red");
      		
      		IButton btn = new IButton("Change Color!");
      		btn.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
            
            public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
              count++;
              if (count%2==0){
              label.setStyleName("green");
              }else{
                label.setStyleName("red");
              }
              label.redraw();
              
            }
          });
      		
      		panel.addMember(label);
      		panel.addMember(btn);
      		
      		panel.draw();
      	}
      the part from the css looks like that:
      Code:
      .red{
        color:red;
      }
      .green{
        color:green;
      }
      If I use a GWT-Label, it works perfect, but not with the SmartGWT-Label.
      Does anyone know what is wrong?

      Thanks,
      Gilbert

      Comment


        #4
        I need to us the smart gwt lavbel because i have to show an icon ( which is not supported by simple gwt label), so I/m forced to find a workaound to make this work.

        Does anybody has a workaround for this problem?


        Originally posted by GilbertGrape
        Hi,

        it was not my thread, but I have exactly the same problem, so I use this one. Hope, thats ok.

        this is my example:

        Code:
        private count;
        public void onModuleLoad() {
        		HLayout panel = new HLayout(20);
        		count = 0;
        		panel.setWidth100();
        		panel.setHeight100();
        		final com.smartgwt.client.widgets.Label label = new com.smartgwt.client.widgets.Label();
        		label.setContents("TEST");
        		label.setStyleName("red");
        		
        		IButton btn = new IButton("Change Color!");
        		btn.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
              
              public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
                count++;
                if (count%2==0){
                label.setStyleName("green");
                }else{
                  label.setStyleName("red");
                }
                label.redraw();
                
              }
            });
        		
        		panel.addMember(label);
        		panel.addMember(btn);
        		
        		panel.draw();
        	}
        the part from the css looks like that:
        Code:
        .red{
          color:red;
        }
        .green{
          color:green;
        }
        If I use a GWT-Label, it works perfect, but not with the SmartGWT-Label.
        Does anyone know what is wrong?

        Thanks,
        Gilbert

        Comment

        Working...
        X