繁体   English   中英

带按钮的GWT PopupPanel

[英]GWT PopupPanel with Buttons

我有一个扩展smartgwt ImgButton的类。 当按下按钮时,应显示一个包含其他按钮的弹出窗口。 此弹出窗口中的按钮不应像普通按钮那样呈现,而应像文本链接一样呈现-因此我应用了自定义CSS类。 到目前为止一切正常。 但是,当我按下弹出窗口中的任何按钮时,按钮的背景将变为透明,并且弹出窗口后面的文本会照亮。 这很丑陋,但我找不到解决此问题的方法。

有没有人知道如何在按下按钮时保持背景色?

这是代码:

import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;

public class MultiButton extends ImgButton {

    private PopupPanel popup;
    private VerticalPanel content;

    public MultiButton() {
        super();
        popup = new PopupPanel();
        popup.setAnimationEnabled(true);
        popup.setAutoHideEnabled(true);

        content = new VerticalPanel();
        popup.add(content);

        this.setWidth(18);
        this.setHeight(18);
        this.setShowRollOver(false);
        this.setShowDown(false);
        this.setSrc("person.png");
        this.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(final ClickEvent event) {
                popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() {

                    @Override
                    public void setPosition(int offsetWidth, int offsetHeight) {
                        int left = event.getX() + 7;
                        int top = event.getY() + 7;

                        popup.setPopupPosition(left, top);
                    }
                });
            }
        });
    }

    public void addMultiButtonEntry(String name, ClickHandler handler) {        
        Button b = new Button(popup.getStyleName());
        b.addClickHandler(handler);

        b.setShowHover(false);
        b.setShowRollOver(false);

        b.setBaseStyle("nt-multibutton-button");

        b.setAlign(Alignment.LEFT);

        content.add(b);
    }
}

这是CSS定义:

.nt-multibutton-button {
    border: 0px !important;
    color: #657380;
    font-size: 11px;
    font-weight: bold;
    text-align: left;
    padding-left: 5px;
    width:90%;
    background-color: white;    
}

谢谢您的每一个提示!

PS:我知道混合SmartGWT和GWT组件不是很好的样式,但是我没有在SmartGWT中找到PopUp,也不想自己编写代码。

我刚刚发现了如何做。

我在按钮上添加了样式主要名称和样式名称,现在可以使用了:)

因此,现在将如下所示创建弹出按钮:

    Button b = new Button(name);
    b.addClickHandler(handler);

    b.setShowHover(false);
    b.setShowRollOver(false);

    String css = "nt-multibutton-button";
    b.setStylePrimaryName(css);
    b.setBaseStyle(css);
    b.setStyleName(css);

    b.setAlign(Alignment.LEFT);

    content.add(b);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM