2013-04-08 73 views
2

我得到這個代碼:在GWT,改變標籤的背景,當鼠標懸停

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"); 

但什麼也沒發生,所以有什麼錯在我的代碼?

任何人都可以幫助我解決它嗎?

回答

4

您需要將鼠標處理程序註冊到Label。

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

的#盈實際上這將是'lb.addMouse ...(磅)的''而不是this'。 – 2013-04-08 05:47:05

0
label.addStyleName("labelStyle"); 

.labelStyle : Hover { 

background : url("Mention your image"); 

} 
相關問題