Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><s>Yes there is</s> </p> <p>No there isn't - at least not without fiddling with GWT's DialogBox class itself or by recreating the DialogBox using common widgets. This is a known issue in GWT, aka <a href="http://code.google.com/p/google-web-toolkit/issues/detail?id=1405" rel="nofollow noreferrer">issue 1405</a> (Star it to show your interest). </p> <p><s>However; DialogBox doesn't give us the tools to do this so we need to extend it</s> - <strong>Edit:</strong> <em>this doesn't work.</em> </p> <p>If you want to make a drop-in replacement for DialogBox you can name your class DialogBox and import it instead of the one that's included in GWT. <s><a href="http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/aae365722c98a664" rel="nofollow noreferrer">This thread</a> on the GWT forum gives better details on how this can be done (outdated, uses listeners)</s> Outdated, the internals of DialogBox have been changed a lot since this thread - it doesn't work.</p> <p><s>Here's some code I hacked to get the same results (used the linked thread for guidance)</s>. This doesn't work:</p> <p><strong>MyDialogBox:</strong></p> <pre><code>import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.MouseOutEvent; import com.google.gwt.event.dom.client.MouseOutHandler; import com.google.gwt.event.dom.client.MouseOverEvent; import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.DialogBox; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Widget; public class MyDialogBox extends DialogBox { private class crossHandler implements ClickHandler, MouseOverHandler, MouseOutHandler { @Override public void onClick(ClickEvent event) { hide(); Window.alert("Click!"); } @Override public void onMouseOver(MouseOverEvent event) { DOM.setStyleAttribute(cross.getElement(), "font-weight", "bold"); } @Override public void onMouseOut(MouseOutEvent event) { DOM.setStyleAttribute(cross.getElement(), "font-weight", "normal"); } } Label cross = new Label("X"); // The close button crossHandler crosshandler = new crossHandler(); HTML caption = new HTML(); // The caption aka title HorizontalPanel captionPanel = new HorizontalPanel(); // Contains caption and cross /** * Creates an empty dialog box. It should not be shown until its child widget * has been added using {@link #add(Widget)}. */ public MyDialogBox() { this(false); } /** * Creates an empty dialog box specifying its "auto-hide" property. It should * not be shown until its child widget has been added using * {@link #add(Widget)}. * * @param autoHide &lt;code&gt;true&lt;/code&gt; if the dialog should be automatically * hidden when the user clicks outside of it */ public MyDialogBox(boolean autoHide) { this(autoHide, true); } /** * Creates an empty dialog box specifying its "auto-hide" property. It should * not be shown until its child widget has been added using * {@link #add(Widget)}. * * @param autoHide &lt;code&gt;true&lt;/code&gt; if the dialog should be automatically * hidden when the user clicks outside of it * @param modal &lt;code&gt;true&lt;/code&gt; if keyboard and mouse events for widgets not * contained by the dialog should be ignored */ public MyDialogBox(boolean autoHide, boolean modal) { super(autoHide, modal); cross.addClickHandler(crosshandler); cross.addMouseOutHandler(crosshandler); cross.addMouseOverHandler(crosshandler); captionPanel.add(caption); captionPanel.add(cross); captionPanel.setStyleName("caption"); Element td = getCellElement(0, 1); // Get the cell element that holds the caption td.setInnerHTML(""); // Remove the old caption td.appendChild(captionPanel.getElement()); } @Override public void setText(String text) { caption.setText(text); } public String getText() { return caption.getText(); } public void setHtml(String html) { caption.setHTML(html); } public String getHtml() { return caption.getHTML(); } </code></pre> <p><strong>Note:</strong> This code doesn't work. The ClickEvent isn't sent from <code>cross</code> but instead from MyDialogBox regardless of whether you add ClickHandlers to the <code>cross</code> or not, IOW the MyDialogBox is the sender/source and therefor not possible to check against <code>cross</code>. When cross is clicked it doesn't fire the ClickEvent for some reasons.</p> <p><strong>Edit:</strong> It appears this cannot be done without hacks unless you either write your own DialogBox (almost) from scratch or fix issue 1405. Of course there are number of existing libraries that have already solved this problem, i.e. <a href="http://www.smartclient.com/smartgwt/showcase/#layout_windows_header_controls" rel="nofollow noreferrer">SmartGWT</a> and <a href="http://www.gwt-ext.com/demo/#layoutWindow" rel="nofollow noreferrer">GWT-Ext</a>, but their implementation is made mostly from scratch.</p> <p>So to answer your question in one sentence: Yes there is a way, but you're not gonna like it :)</p>
 

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