Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can set cursor: hand with GWT: label

I'd like to set a mouse listener to my Label so that I can change the cursor to a HAND_CURSOR when the user places their mouse over a label.

 <g:Label text="Overview" styleName="left_menu_title" ui:field="lb_overview"/>

I tried to set style css "cursor: hand;" for this Label, but when run, all attribute cursor were replaced.

Do you have any suggestion?

like image 355
Jimmy Avatar asked Dec 19 '11 01:12

Jimmy


3 Answers

The answer provided by user1557828 will in fact cause the Label to show the cursor when the mouse is over it, but there is a simpler way to achieve the same result:

Label testLabel = new Label("Text Goes Here);
testLabel.getElement().getStyle().setCursor(Cursor.POINTER); 

This will set the cursor at instantiation and the style will persist. It is not necessary to re-apply the style each time the mouse moves over the label.

like image 120
TheGrandPackard Avatar answered Oct 27 '22 01:10

TheGrandPackard


The proper way to do it would be:

.left_menu_title {
   cursor: pointer;
}

and

<g:Label text="Overview" styleName="{style.left_menu_title}" ui:field="lb_overview"/>
like image 2
Chris Cashwell Avatar answered Oct 27 '22 00:10

Chris Cashwell


where to this one..
Label testLabel = new Label("Text Goes Here);
testLabel.getElement().getStyle().setCursor(Cursor.POINTER); 

in my code provided below..

 {
   xtype:'label',
   text:'testLabel',
   id:'cancel1',
   Label testLabel = new Label("Text Goes Here);  
   testLabel.getElement().getStyle().setCursor(Cursor.POINTER); 
   listeners : {
   render : function(d) {
   d.getEl().on('click', function(){ this.fireEvent('click', d); }, d);
}
}

}
like image 2
krupal Avatar answered Oct 27 '22 01:10

krupal