Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Closing window

    This probably will sound silly, but I was looking for an answer here and I found it in a thread with a misleading title.
    HTMLFlow in Window issues
    I have code like this
    Code:
    		IButton btnAgregar=new IButton("Agregar");
    		btnAgregar.addClickHandler(new ClickHandler(){
    
    			@Override
    			public void onClick(ClickEvent event) {
    				Window frmDetalle=new Window();
    				frmDetalle.setTitle("Agregar datos");
    				frmDetalle.setIsModal(true);
    				frmDetalle.setSize("50%", "50%");
    				frmDetalle.centerInPage();
    				frmDetalle.show();
    			}
    			
    		});
    Inside the window I have a button which "closes" it, since I'm creating a new Window instance every time, I call destroy to close and dispose it (besides, there's no close method).
    Code:
    		final Window This=this;
    		IButton btnCancelar=new IButton("Cancelar");
    		btnCancelar.addClickHandler(new ClickHandler(){
    
    			@Override
    			public void onClick(ClickEvent event) {
    				This.destroy();
    			}
    			
    		});
    Notice the final variable "This" to access Window methods from ClickHandler anonymous class. As a final note, if you reuse the window instance (aka don't create it on button clicks), just hide it. This is the default behavior for the "X" button on title bar.

    #2
    It is not related to your post but you do not need to assign "this" to final variable. Inside anonymous class you can use YouWindowClass.this.destroy() because it is enclosing type for your clickHandler class.

    Comment


      #3
      Originally posted by lazinskip
      Inside anonymous class you can use YouWindowClass.this.destroy() because it is enclosing type for your clickHandler class.
      Thanks for the tip!
      Obviously, I didn't know that. Works great!

      Comment

      Working...
      X