public void setImage(Image image) { checkWidget(); if ((style & SWT.SEPARATOR) != 0) return; if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); super.setImage(image); updateImages(getEnabled() && parent.getEnabled()); }
/** * Sets the image that the receiver will use to paint the caret to the image specified by the * argument, or to the default which is a filled rectangle if the argument is null * * @param image the new image (or null) * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setImage(Image image) { checkWidget(); if (image != null && image.isDisposed()) { error(SWT.ERROR_INVALID_ARGUMENT); } this.image = image; if (image != null) { OS.Image_Source(imageHandle, image.handle); OS.UIElement_Visibility(imageHandle, OS.Visibility_Visible); } else { OS.Image_Source(imageHandle, 0); OS.UIElement_Visibility(imageHandle, OS.Visibility_Collapsed); } resize(width, height); }
/** * Sets the receiver's image to the argument, which may be <code>null</code> indicating that no * image should be displayed. * * <p>Note that a Button can display an image and text simultaneously on Windows (starting with * XP), GTK+ and OSX. On other platforms, a Button that has an image and text set into it will * display the image or text that was set most recently. * * @param image the image to display on the receiver (may be <code>null</code>) * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setImage(Image image) { checkWidget(); if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); if ((style & SWT.ARROW) != 0) return; this.image = image; OS.Image_Source(imageHandle, image != null ? image.handle : 0); OS.UIElement_Visibility( imageHandle, image != null ? OS.Visibility_Visible : OS.Visibility_Collapsed); OS.UIElement_Visibility( textHandle, image != null && text.length() == 0 ? OS.Visibility_Collapsed : OS.Visibility_Visible); int spacing = image != null && text.length() != 0 ? 3 : 0; int margin = OS.gcnew_Thickness(0, 0, spacing, 0); if (margin == 0) error(SWT.ERROR_NO_HANDLES); OS.FrameworkElement_Margin(imageHandle, margin); OS.GCHandle_Free(margin); }