Calling FormToolkit.dispose()

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Calling FormToolkit.dispose()

Postby SlowStrider » Thu Apr 22, 2010 8:15 am

When I create a new Composite for the Forms API (using SWT builder 7.3), the initial generated code looks like this:

Code: Select all
import org.eclipse.swt.layout.GridLayout;

public class Temp extends Composite {

   private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());

   /**
    * Create the composite.
    * @param parent
    * @param style
    */
   public Temp(Composite parent, int style) {
      super(parent, style);
      toolkit.adapt(this);
      toolkit.paintBordersFor(this);
      setLayout(new GridLayout());
   }

}


This is working fine for me, but the Javadoc for the FormToolKit constructor states:
/**
* Creates a toolkit that is self-sufficient (will manage its own colors).
* <p>
* Clients that call this method must call {@link #dispose()} when they
* are finished using the toolkit.
*
*/


I don't see the dispose() method getting called. Could this become a problem?
SlowStrider
 
Posts: 1
Joined: Thu Apr 22, 2010 8:10 am

Re: Calling FormToolkit.dispose()

Postby Eric Clayberg » Mon Apr 26, 2010 5:36 am

I have never seen it be a problem, so I don't know.

You can add the following to the constructor...

Code: Select all
      addDisposeListener(new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
            toolkit.dispose();
         }
      });
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: Google [Bot] and 2 guests