我宣佈了一些色彩,爲VerticalLayout的面板邊框,像:GWT UiBinder的CSS樣式
<ui:style>
.onMouseOverBorderColor {border-color: red; border-style: outset}
.onMouseOutBorderColor {border-color: black; border-style: outset}
</ui:style>
然後我想根據鼠標的位置來改變面板的邊框的顏色,和我添加到我的部件的構造函數如下:
clickable.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
GWT.log("mouse over");
border.setStyleName("onMouseOverBorderColor");
}
});
clickable.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
GWT.log("mouse out");
border.setStyleName("onMouseOutBorderColor");
}
});
但是......什麼也沒有發生!我做錯了什麼?
後建議(不工作)代碼:
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.fontStyleTitle {font-weight: bold }
.border {border-color: black; border-style: outset}
.border:hover {border-color: red; border-style: outset}
</ui:style>
<g:FocusPanel ui:field="clickable">
<g:VerticalPanel ui:field="border" borderWidth="1" styleName="style.border">
<g:Image ui:field="myImage"/>
<g:Label ui:field="myTitle" horizontalAlignment="ALIGN_CENTER" styleName="{style.fontStyleTitle}"/>
</g:VerticalPanel>
</g:FocusPanel>
</ui:UiBinder>
和Java類:
public UiWidget(String path, String theTitle) {
initWidget(uiBinder.createAndBindUi(this));
GWT.log(URL_PREFIX+path);
myImage.setUrl(URL_PREFIX+path);
myTitle.setText(theTitle);
myImage.setSize(IMG_WIDTH, IMG_HEIGHT);
/*
clickable.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
GWT.log("mouse over");
}
});
clickable.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
GWT.log("mouse out");
}
*/
}
感謝您的建議,我改變了我的代碼 - 如我原來的帖子所示 - 但我沒有看到預期的效果。代碼是否正確? –
你忘了大括號:'styleName =「{style.border}」' –