Tom
Tom

Reputation: 845

in GWT, change the background of Label when mouseover

I got this code:

private class MyLabel extends Label implements MouseOverHandler, MouseOutHandler {
      public void onMouseOver(final MouseOverEvent moe) {
       this.getElement().getStyle().setBackgroundColor("E6D5D5");

      }



    @Override
    public void onMouseOut(MouseOutEvent event) {
        // TODO Auto-generated method stub
        this.getElement().getStyle().setBackgroundColor("FFFFFF");
    }
}
MyLabel lb=new MyLabel();
lb.setText("ok");

But nothing happened, so what wrong in my code?

Can anyone help me to fix it?

Upvotes: 2

Views: 2386

Answers (3)

user5939360
user5939360

Reputation: 1

Please keep # infront of the color code

Upvotes: 0

Abhijith Nagaraja
Abhijith Nagaraja

Reputation: 3380

label.addStyleName("labelStyle");

.labelStyle : Hover {

 background : url("Mention your image");

}

Upvotes: 1

Jaydeep Rajput
Jaydeep Rajput

Reputation: 3673

You need to register mouse handlers to Label.

lb.addMouseOverHandler(this);
lb.addMouseOutHandler(this);

Upvotes: 4

Related Questions