How to set the cursor: hand with GWT: label

I would like to set the mouse listener to my Lable so that I can change the cursor to HAND_CURSOR when the user hovers over the label.

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

I tried to set the css style "cursor: hand;" for this label, but at startup all attribute cursors have been replaced.

Do you have any suggestions?

+7
source share
4 answers

The answer provided by user1557828 will actually make the shortcut display the cursor when the mouse is over it, but there is an easier way to achieve the same result:

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

This sets the cursor to the instance and the style is saved. There is no need to reapply the style every time the mouse moves over the label.

+19
source

The correct way to do this is:

 .left_menu_title { cursor: pointer; } 

and

 <g:Label text="Overview" styleName="{style.left_menu_title}" ui:field="lb_overview"/> 
+2
source

You need to do the following:

 .left_menu_title { cursor: pointer; } 

If you want the code to perform other actions besides a pointer to a pointer:

 import com.google.gwt.dom.client.Style.Cursor; import com.google.gwt.event.dom.client.MouseOverEvent; import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.user.client.ui.Label; ... ... ... final Label testLabel = new Label(); testLabel.addMouseOverHandler(new MouseOverHandler() { @Override public void onMouseOver(MouseOverEvent event) { testLabel.getElement().getStyle().setCursor(Cursor.POINTER); //TODO: any thing you want } }); 
+2
source
 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); } } } 
+2
source

All Articles