我想为我的标签设置一个鼠标监听器,以便当用户将鼠标放在标签上时可以将光标更改为HAND_CURSOR。如何设置光标:手用GWT:标签
<g:Label text="Overview" styleName="left_menu_title" ui:field="lb_overview"/>
我试着设置风格的CSS“光标:手;”对于此标签,但运行时,所有属性光标均被替换。
你有什么建议吗?
我想为我的标签设置一个鼠标监听器,以便当用户将鼠标放在标签上时可以将光标更改为HAND_CURSOR。如何设置光标:手用GWT:标签
<g:Label text="Overview" styleName="left_menu_title" ui:field="lb_overview"/>
我试着设置风格的CSS“光标:手;”对于此标签,但运行时,所有属性光标均被替换。
你有什么建议吗?
正确的方式做这将是:
.left_menu_title {
cursor: pointer;
}
和
<g:Label text="Overview" styleName="{style.left_menu_title}" ui:field="lb_overview"/>
正如我所说的光标的所有属性被替换。即使“光标:点” “光标:手;” – Jimmy 2011-12-19 01:45:14
添加了标签样式规则。你并没有宣布这个标签是正确的。 – 2011-12-19 11:23:03
您应该使用'addStylesNames'而不是'styleName',但这与此处讨论的问题无关;只是一个供参考。 – 2011-12-19 11:24:41
你只需做到以下几点:
.left_menu_title {
cursor: 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
}
});
通过user1557828提供的答案将在事实上导致标签显示光标,当鼠标移动到它,但有一个简单的方法来达到同样的效果:
Label testLabel = new Label("Text Goes Here);
testLabel.getElement().getStyle().setCursor(Cursor.POINTER);
这将设置实例化的游标和样式将会持续。每当鼠标移过标签时,不必重新应用样式。
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);
}
}
}
我已经在我的代码中尝试了这一点,但它不工作PLZ给我合适的答案在哪里把它放在我的代码中... – krupal 2012-10-01 07:01:49
你的意思是css“cursor:pointer”? – 2011-12-19 01:32:34
我试过“光标:点”和“光标:手”,但它仍然被替换 – Jimmy 2011-12-19 01:54:39
添加'cursor:pointer!important;'强制你的CSS样式,如果别的东西覆盖它。 – Strelok 2011-12-19 03:03:09