Java Code Examples for org.eclipse.swt.widgets.Button.addDisposeListener()

The following are Jave code examples for showing how to use addDisposeListener() of the org.eclipse.swt.widgets.Button class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: n4js   File: ButtonFactoryUtil.java   View Source Code Vote up 5 votes
/**
 * Creates button with {@link org.eclipse.swt.SWT#PUSH} style. Provided parameters control other aspects of the
 * button.
 *
 * @param parent
 *            the parent used to create the button.
 * @param text
 *            the text used to set text of the button.
 * @param listener
 *            the listener added to the button.
 * @param enabled
 *            flag controls if created button is enabled.
 * @return created button.
 */
public static Button createPushButton(final Composite parent, final String text, final SelectionListener listener,
		boolean enabled) {
	final Button button = new Button(parent, PUSH);
	button.setLayoutData(fillDefaults().align(FILL, CENTER).create());
	button.setText(text);
	if (null != listener) {
		button.addSelectionListener(listener);
		button.addDisposeListener(e -> {
			button.removeSelectionListener(listener);
		});
	}
	button.setEnabled(enabled);
	return button;
}
 
Example 2
Project: BiglyBT   File: ImageLoader.java   View Source Code Vote up 5 votes
public Image setButtonImage(Button btn, final String key) {
	Image bg = getImage(key);
	btn.setImage(bg);
	btn.addDisposeListener(new DisposeListener() {
		@Override
		public void widgetDisposed(DisposeEvent e) {
			releaseImage(key);
		}
	});

	return( bg );
}