2011-12-19 5 views
7

Vorrei impostare un ascoltatore del mouse su Lable in modo da poter cambiare il cursore su HAND_CURSOR quando l'utente posiziona il mouse su un'etichetta.Come impostare il cursore: mano con GWT: etichetta

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

Ho cercato di impostare lo stile css "cursor: hand;" per questa etichetta, ma quando è stato eseguito, tutti i cursori degli attributi sono stati sostituiti.

Avete qualche suggerimento?

+0

Vuoi dire css "cursor: pointer"? –

+0

Ho provato "cursor: point" e "cursor: hand" ma è stato comunque sostituito – Jimmy

+1

aggiungi 'cursor: pointer! Important;' per forzare il tuo stile CSS se qualcos'altro lo sta sovrascrivendo. – Strelok

risposta

2

Il modo corretto per farlo sarebbe:

.left_menu_title { 
    cursor: pointer; 
} 

e

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

Come ho detto, tutti gli attributi del cursore sono stati sostituiti. Anche "cursor: point;" "cursor: hand;" – Jimmy

+0

aggiunta regola dello stile etichetta. Non lo stavi dichiarando giusto per l'etichetta. –

+1

Probabilmente dovresti usare 'addStylesNames' piuttosto che' styleName', ma questo è indipendente dal problema discusso qui; solo una FYI. –

2

devi solo effettuare le seguenti operazioni:

.left_menu_title { 
cursor: pointer; 
} 

se si vuole un codice per fare altra cosa di impostare il cursore sul puntatore:

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  
     } 
    }); 
19

La risposta fornita da user1557828 sarà infatti causare l'etichetta per mostrare il cursore quando il mouse è sopra esso, ma c'è un modo più semplice per ottenere lo stesso risultato:

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

Questo imposterà il cursore all'istanziazione e lo stile persisterà. Non è necessario riapplicare lo stile ogni volta che il mouse si sposta sull'etichetta.

2
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); 
} 
} 

} 
+0

ho provato questo nel mio codice ma non funziona plz dammi la risposta appropriata dove metterlo nel mio codice ... – krupal