Composite composite = new Composite(parent, SWT.NONE); // use composite composite.dispose(); if (!composite.isDisposed()) { System.out.println("Composite object has not been disposed of."); } else { System.out.println("Composite object has been disposed of."); }
public void widgetDisposed(DisposeEvent e) { if (composite != null && !composite.isDisposed()) { composite.dispose(); } }In this example, the .widgetDisposed() method is called when a widget is disposed of. The method checks whether or not a Composite object exists and, if it does, whether or not it has been disposed of using the .isDisposed() method. If the object has not been disposed of, the .dispose() method is called to dispose of it. The org.eclipse.swt.widgets package library is used in this example.