简体   繁体   English

在GWT中,将鼠标悬停时更改Label的背景

[英]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? 谁能帮我修复它?

You need to register mouse handlers to Label. 您需要将鼠标处理程序注册到Label。

lb.addMouseOverHandler(this);
lb.addMouseOutHandler(this);
label.addStyleName("labelStyle");

.labelStyle : Hover {

 background : url("Mention your image");

}

请在颜色代码的前面保持#号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM