How to add a close button to the caption bar of a GWT DialogBox [duplicate]

拈花ヽ惹草 提交于 2019-12-24 09:17:42

问题


I need to add a close button to the caption bar of my dialog box . I'm able to place a widget in the caption bar , but not been able to get the events for it .


回答1:


http://zone817.blogspot.com/2010/08/close-button-in-caption-bar-of-gwt.html

seems like exactly what you want.




回答2:


Here is a modification of the example given by amal. This code retains gwt-DialogBox caption style.

public class CloseButtonDialogBox extends DialogBox {

private Node closeEventTarget = null;

public CloseButtonDialogBox() {
    // get the "dialogTopRight" class td
    Element dialogTopRight = getCellElement(0, 2);

    // close button image html
    dialogTopRight.setInnerHTML(
            "<div style=\"margin-left:-25px;margin-top: 7px;\">" + 
            "<img src=\"images/closebutton.png\" height=\"20px\"/>" + 
            "</div>");

    // set the event target
    closeEventTarget = dialogTopRight.getChild(0).getChild(0);
}

@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();

    if (!event.isCanceled() 
            && (event.getTypeInt() == Event.ONCLICK)
            && isCloseEvent(nativeEvent))
    {
        this.hide();
    }
    super.onPreviewNativeEvent(event);
}

// see if the click target is the close button
private boolean isCloseEvent(NativeEvent event) {
    return event.getEventTarget().equals(closeEventTarget); //compares equality of the underlying DOM elements
}   



回答3:


See the answer posted in the linked question. It shows the proper way to do this by implementing the DialogBox.Caption interface and then adding an event handler to your caption implementation for the included close button that hides the dialog box.

This did the trick for me.

https://stackoverflow.com/a/7960172/458426



来源:https://stackoverflow.com/questions/3597726/how-to-add-a-close-button-to-the-caption-bar-of-a-gwt-dialogbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!