Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess a simple answer to this is to instantiate a widget to replace the standard Caption widget from DialogBox. I created a caption that has a button at right and you can pick a reference to it. Then you can add any click event you desire.</p> <p>In GWT 2.4 I used the following solution:</p> <pre><code>import com.google.gwt.event.dom.client.MouseDownHandler; import com.google.gwt.event.dom.client.MouseMoveHandler; import com.google.gwt.event.dom.client.MouseOutHandler; import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.event.dom.client.MouseUpHandler; import com.google.gwt.event.dom.client.MouseWheelHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.InlineLabel; import com.google.gwt.user.client.ui.PushButton; import com.google.gwt.user.client.ui.DialogBox.Caption; /** * @author Cristiano Sumariva */ public class ButtonCaption extends HorizontalPanel implements Caption { protected InlineLabel text; protected PushButton closeDialog; /** * @return the button at caption */ public PushButton getCloseButton() { return closeDialog; } public ButtonCaption( String label ) { super(); setWidth( "100%" ); setStyleName( "Caption" ); // so you have same styling as standard caption widget closeDialog = new PushButton(); add( text = new InlineLabel( label ) ); add( closeDialog ); setCellWidth( closeDialog, "1px" ); // to make button cell minimal enough to it } /* (non-Javadoc) * @see com.google.gwt.event.dom.client.HasMouseDownHandlers#addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler) */ @Override public HandlerRegistration addMouseDownHandler( MouseDownHandler handler ) { return addMouseDownHandler( handler ); } /* (non-Javadoc) * @see com.google.gwt.event.dom.client.HasMouseUpHandlers#addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) */ @Override public HandlerRegistration addMouseUpHandler( MouseUpHandler handler ) { return addMouseUpHandler( handler ); } /* (non-Javadoc) * @see com.google.gwt.event.dom.client.HasMouseOutHandlers#addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) */ @Override public HandlerRegistration addMouseOutHandler( MouseOutHandler handler ) { return addMouseOutHandler( handler ); } /* (non-Javadoc) * @see com.google.gwt.event.dom.client.HasMouseOverHandlers#addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler) */ @Override public HandlerRegistration addMouseOverHandler( MouseOverHandler handler ) { return addMouseOverHandler( handler ); } /* (non-Javadoc) * @see com.google.gwt.event.dom.client.HasMouseMoveHandlers#addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler) */ @Override public HandlerRegistration addMouseMoveHandler( MouseMoveHandler handler ) { return addMouseMoveHandler( handler ); } /* (non-Javadoc) * @see com.google.gwt.event.dom.client.HasMouseWheelHandlers#addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler) */ @Override public HandlerRegistration addMouseWheelHandler( MouseWheelHandler handler ) { return addMouseWheelHandler( handler ); } /* (non-Javadoc) * @see com.google.gwt.user.client.ui.HasHTML#getHTML() */ @Override public String getHTML() { return getElement().getInnerHTML(); } /* (non-Javadoc) * @see com.google.gwt.user.client.ui.HasHTML#setHTML(java.lang.String) */ @Override public void setHTML( String html ) { remove( text ); insert( text, 1 ); } /* (non-Javadoc) * @see com.google.gwt.user.client.ui.HasText#getText() */ @Override public String getText() { return text.getText(); } /* (non-Javadoc) * @see com.google.gwt.user.client.ui.HasText#setText(java.lang.String) */ @Override public void setText( String text ) { this.text.setText( text ); } /* (non-Javadoc) * @see com.google.gwt.safehtml.client.HasSafeHtml#setHTML(com.google.gwt.safehtml.shared.SafeHtml) */ @Override public void setHTML( SafeHtml html ) { setHTML( html.asString() ); } } </code></pre> <p>Extends the DialogBox to use the new ButtonCaption available</p> <pre><code>class CaptionCloseableDialogBox extends DialogBox { public CaptionCloseableDialogBox() { super( new ButtonCaption( "dialog box title" ) ); setAutoHideEnabled( false ); ButtonCaption ref = (ButtonCaption) this.getCaption(); PushButton closeButton = ref.getCloseButton(); // apply button face here closeButton; closeButton.addClickHandler( /* attach any click handler here like close this dialog */ ); } } </code></pre> <p>Hope it helps any.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload