Class Control

java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
All Implemented Interfaces:
Drawable
Direct Known Subclasses:
Button, Label, Link, ProgressBar, Sash, Scale, Scrollable, Slider

public abstract class Control extends Widget implements Drawable
Control is the abstract superclass of all windowed user interface classes.
Styles:
BORDER
LEFT_TO_RIGHT, RIGHT_TO_LEFT, FLIP_TEXT_DIRECTION
Events:
DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter, MouseExit, MouseHover, MouseUp, MouseMove, MouseWheel, MouseHorizontalWheel, MouseVerticalWheel, Move, Paint, Resize, Traverse

Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.

IMPORTANT: This class is intended to be subclassed only within the SWT implementation.

See Also:
Restriction:
This class is not intended to be subclassed by clients.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    long
    the handle to the OS resource (Warning: This field is platform dependent)

    Fields inherited from class org.eclipse.swt.widgets.Widget

    nativeZoom
  • Constructor Summary

    Constructors
    Constructor
    Description
    Control(Composite parent, int style)
    Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds the listener to the collection of listeners who will be notified when the control is moved or resized, by sending it one of the messages defined in the ControlListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when a drag gesture occurs, by sending it one of the messages defined in the DragDetectListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when the control gains or loses focus, by sending it one of the messages defined in the FocusListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when gesture events are generated for the control, by sending it one of the messages defined in the GestureListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when help events are generated for the control, by sending it one of the messages defined in the HelpListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when keys are pressed and released on the system keyboard, by sending it one of the messages defined in the KeyListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when the platform-specific context menu trigger has occurred, by sending it one of the messages defined in the MenuDetectListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when mouse buttons are pressed and released, by sending it one of the messages defined in the MouseListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when the mouse moves, by sending it one of the messages defined in the MouseMoveListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when the mouse passes or hovers over controls, by sending it one of the messages defined in the MouseTrackListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when the mouse wheel is scrolled, by sending it one of the messages defined in the MouseWheelListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when the receiver needs to be painted, by sending it one of the messages defined in the PaintListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when touch events occur, by sending it one of the messages defined in the TouchListener interface.
    void
    Adds the listener to the collection of listeners who will be notified when traversal events occur, by sending it one of the messages defined in the TraverseListener interface.
    computeSize(int wHint, int hHint)
    Returns the preferred size (in points) of the receiver.
    computeSize(int wHint, int hHint, boolean changed)
    Returns the preferred size (in points) of the receiver.
    boolean
    Detects a drag and drop gesture.
    boolean
    Detects a drag and drop gesture.
    boolean
    Forces the receiver to have the keyboard focus, causing all keyboard events to be delivered to it.
    Returns the accessible object for the receiver.
    Returns the receiver's background color.
    Returns the receiver's background image.
    int
    Returns the receiver's border width in points.
    Returns a rectangle describing the receiver's size and location in points relative to its parent (or its display if its parent is null), unless the receiver is a shell.
    Returns the receiver's cursor, or null if it has not been set.
    boolean
    Returns true if the receiver is detecting drag gestures, and false otherwise.
    boolean
    Returns true if the receiver is enabled, and false otherwise.
    Returns the font that the receiver will use to paint textual information.
    Returns the foreground color that the receiver will use to draw.
    Returns layout data which is associated with the receiver.
    Returns a point describing the receiver's location relative to its parent in points (or its display if its parent is null), unless the receiver is a shell.
    Returns the receiver's pop up menu if it has one, or null if it does not.
    Returns the receiver's monitor.
    int
    Returns the orientation of the receiver, which will be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
    Returns the receiver's parent, which must be a Composite or null when the receiver is a shell that was created with null or a display for a parent.
    Returns the region that defines the shape of the control, or null if the control has the default shape.
    Returns the receiver's shell.
    Returns a point describing the receiver's size in points.
    int
    Returns the text direction of the receiver, which will be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
    Returns the receiver's tool tip text, or null if it has not been set.
    boolean
    Returns true if this control is set to send touch events, or false if it is set to send gesture events instead.
    boolean
    Returns true if the receiver is visible, and false otherwise.
    void
    internal_dispose_GC(long hDC, GCData data)
    Invokes platform specific functionality to dispose a GC handle.
    long
    Invokes platform specific functionality to allocate a new GC handle.
    boolean
    Returns true if the receiver is enabled and all ancestors up to and including the receiver's nearest ancestor shell are enabled.
    boolean
    Returns true if the receiver has the user-interface focus, and false otherwise.
    boolean
    Returns true if the underlying operating system supports this reparenting, otherwise false
    boolean
    Returns true if the receiver is visible and all ancestors up to and including the receiver's nearest ancestor shell are visible.
    void
    moveAbove(Control control)
    Moves the receiver above the specified control in the drawing order.
    void
    moveBelow(Control control)
    Moves the receiver below the specified control in the drawing order.
    void
    Causes the receiver to be resized to its preferred size.
    void
    pack(boolean changed)
    Causes the receiver to be resized to its preferred size.
    boolean
    print(GC gc)
    Prints the receiver and all children.
    void
    Causes the entire bounds of the receiver to be marked as needing to be redrawn.
    void
    redraw(int x, int y, int width, int height, boolean all)
    Causes the rectangular area of the receiver specified by the arguments to be marked as needing to be redrawn.
    void
    Removes the listener from the collection of listeners who will be notified when the control is moved or resized.
    void
    Removes the listener from the collection of listeners who will be notified when a drag gesture occurs.
    void
    Removes the listener from the collection of listeners who will be notified when the control gains or loses focus.
    void
    Removes the listener from the collection of listeners who will be notified when gesture events are generated for the control.
    void
    Removes the listener from the collection of listeners who will be notified when the help events are generated for the control.
    void
    Removes the listener from the collection of listeners who will be notified when keys are pressed and released on the system keyboard.
    void
    Removes the listener from the collection of listeners who will be notified when the platform-specific context menu trigger has occurred.
    void
    Removes the listener from the collection of listeners who will be notified when mouse buttons are pressed and released.
    void
    Removes the listener from the collection of listeners who will be notified when the mouse moves.
    void
    Removes the listener from the collection of listeners who will be notified when the mouse passes or hovers over controls.
    void
    Removes the listener from the collection of listeners who will be notified when the mouse wheel is scrolled.
    void
    Removes the listener from the collection of listeners who will be notified when the receiver needs to be painted.
    void
    Removes the listener from the collection of listeners who will be notified when touch events occur.
    void
    Removes the listener from the collection of listeners who will be notified when traversal events occur.
    void
    Requests that this control and all of its ancestors be repositioned by their layouts at the earliest opportunity.
    void
    Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null.
    void
    Sets the receiver's background image to the image specified by the argument, or to the default system color for the control if the argument is null.
    void
    setBounds(int x, int y, int width, int height)
    Sets the receiver's size and location in points to the rectangular area specified by the arguments.
    void
    Sets the receiver's size and location in points to the rectangular area specified by the argument.
    void
    setCapture(boolean capture)
    If the argument is true, causes the receiver to have all mouse events delivered to it until the method is called with false as the argument.
    void
    setCursor(Cursor cursor)
    Sets the receiver's cursor to the cursor specified by the argument, or to the default cursor for that kind of control if the argument is null.
    void
    setDragDetect(boolean dragDetect)
    Sets the receiver's drag detect state.
    void
    setEnabled(boolean enabled)
    Enables the receiver if the argument is true, and disables it otherwise.
    boolean
    Causes the receiver to have the keyboard focus, such that all keyboard events will be delivered to it.
    void
    setFont(Font font)
    Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.
    void
    Sets the receiver's foreground color to the color specified by the argument, or to the default system color for the control if the argument is null.
    void
    setLayoutData(Object layoutData)
    Sets the layout data associated with the receiver to the argument.
    void
    setLocation(int x, int y)
    Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell.
    void
    setLocation(Point location)
    Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell.
    void
    setMenu(Menu menu)
    Sets the receiver's pop up menu to the argument.
    void
    setOrientation(int orientation)
    Sets the orientation of the receiver, which must be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
    boolean
    Changes the parent of the widget to be the one provided.
    void
    setRedraw(boolean redraw)
    If the argument is false, causes subsequent drawing operations in the receiver to be ignored.
    void
    setRegion(Region region)
    Sets the shape of the control to the region specified by the argument.
    void
    setSize(int width, int height)
    Sets the receiver's size to the point specified by the arguments.
    void
    setSize(Point size)
    Sets the receiver's size to the point specified by the argument.
    void
    setTextDirection(int textDirection)
    Sets the base text direction (a.k.a.
    void
    Sets the receiver's tool tip text to the argument, which may be null indicating that the default tool tip for the control will be shown.
    void
    setTouchEnabled(boolean enabled)
    Sets whether this control should send touch events (by default controls do not).
    void
    setVisible(boolean visible)
    Marks the receiver as visible if the argument is true, and marks it invisible otherwise.
    toControl(int x, int y)
    Returns a point which is the result of converting the argument, which is specified in display relative coordinates, to coordinates relative to the receiver.
    Returns a point which is the result of converting the argument, which is specified in display relative coordinates, to coordinates relative to the receiver.
    toDisplay(int x, int y)
    Returns a point which is the result of converting the argument, which is specified in coordinates relative to the receiver, to display relative coordinates.
    Returns a point which is the result of converting the argument, which is specified in coordinates relative to the receiver, to display relative coordinates.
    boolean
    traverse(int traversal)
    Based on the argument, perform one of the expected platform traversal action.
    boolean
    traverse(int traversal, KeyEvent event)
    Performs a platform traversal action corresponding to a KeyDown event.
    boolean
    traverse(int traversal, Event event)
    Performs a platform traversal action corresponding to a KeyDown event.
    void
    Forces all outstanding paint requests for the widget to be processed before this method returns.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.swt.graphics.Drawable

    isAutoScalable
  • Field Details

    • handle

      public long handle
      the handle to the OS resource (Warning: This field is platform dependent)

      IMPORTANT: This field is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms and should never be accessed from application code.

      Restriction:
      This field is not intended to be referenced by clients.
  • Constructor Details

    • Control

      public Control(Composite parent, int style)
      Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

      The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
      style - the style of control to construct
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the parent is null
      SWTException -
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
      • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
      See Also:
  • Method Details

    • addControlListener

      public void addControlListener(ControlListener listener)
      Adds the listener to the collection of listeners who will be notified when the control is moved or resized, by sending it one of the messages defined in the ControlListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addDragDetectListener

      public void addDragDetectListener(DragDetectListener listener)
      Adds the listener to the collection of listeners who will be notified when a drag gesture occurs, by sending it one of the messages defined in the DragDetectListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
      See Also:
    • addFocusListener

      public void addFocusListener(FocusListener listener)
      Adds the listener to the collection of listeners who will be notified when the control gains or loses focus, by sending it one of the messages defined in the FocusListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addGestureListener

      public void addGestureListener(GestureListener listener)
      Adds the listener to the collection of listeners who will be notified when gesture events are generated for the control, by sending it one of the messages defined in the GestureListener interface.

      NOTE: If setTouchEnabled(true) has previously been invoked on the receiver then setTouchEnabled(false) must be invoked on it to specify that gesture events should be sent instead of touch events.

      Warning: This API is currently only implemented on Windows and Cocoa. SWT doesn't send Gesture or Touch events on GTK.

      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.7
      See Also:
    • addHelpListener

      public void addHelpListener(HelpListener listener)
      Adds the listener to the collection of listeners who will be notified when help events are generated for the control, by sending it one of the messages defined in the HelpListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addKeyListener

      public void addKeyListener(KeyListener listener)
      Adds the listener to the collection of listeners who will be notified when keys are pressed and released on the system keyboard, by sending it one of the messages defined in the KeyListener interface.

      When a key listener is added to a control, the control will take part in widget traversal. By default, all traversal keys (such as the tab key and so on) are delivered to the control. In order for a control to take part in traversal, it should listen for traversal events. Otherwise, the user can traverse into a control but not out. Note that native controls such as table and tree implement key traversal in the operating system. It is not necessary to add traversal listeners for these controls, unless you want to override the default traversal.

      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addMenuDetectListener

      public void addMenuDetectListener(MenuDetectListener listener)
      Adds the listener to the collection of listeners who will be notified when the platform-specific context menu trigger has occurred, by sending it one of the messages defined in the MenuDetectListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
      See Also:
    • addMouseListener

      public void addMouseListener(MouseListener listener)
      Adds the listener to the collection of listeners who will be notified when mouse buttons are pressed and released, by sending it one of the messages defined in the MouseListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addMouseTrackListener

      public void addMouseTrackListener(MouseTrackListener listener)
      Adds the listener to the collection of listeners who will be notified when the mouse passes or hovers over controls, by sending it one of the messages defined in the MouseTrackListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addMouseMoveListener

      public void addMouseMoveListener(MouseMoveListener listener)
      Adds the listener to the collection of listeners who will be notified when the mouse moves, by sending it one of the messages defined in the MouseMoveListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addMouseWheelListener

      public void addMouseWheelListener(MouseWheelListener listener)
      Adds the listener to the collection of listeners who will be notified when the mouse wheel is scrolled, by sending it one of the messages defined in the MouseWheelListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
      See Also:
    • addPaintListener

      public void addPaintListener(PaintListener listener)
      Adds the listener to the collection of listeners who will be notified when the receiver needs to be painted, by sending it one of the messages defined in the PaintListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • addTouchListener

      public void addTouchListener(TouchListener listener)
      Adds the listener to the collection of listeners who will be notified when touch events occur, by sending it one of the messages defined in the TouchListener interface.

      NOTE: You must also call setTouchEnabled(true) to specify that touch events should be sent, which will cause gesture events to not be sent.

      Warning: This API is currently only implemented on Windows and Cocoa. SWT doesn't send Gesture or Touch events on GTK.

      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.7
      See Also:
    • addTraverseListener

      public void addTraverseListener(TraverseListener listener)
      Adds the listener to the collection of listeners who will be notified when traversal events occur, by sending it one of the messages defined in the TraverseListener interface.
      Parameters:
      listener - the listener which should be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • computeSize

      public Point computeSize(int wHint, int hHint)
      Returns the preferred size (in points) of the receiver.

      The preferred size of a control is the size that it would best be displayed at. The width hint and height hint arguments allow the caller to ask a control questions such as "Given a particular width, how high does the control need to be to show all of the contents?" To indicate that the caller does not wish to constrain a particular dimension, the constant SWT.DEFAULT is passed for the hint.

      Parameters:
      wHint - the width hint (can be SWT.DEFAULT)
      hHint - the height hint (can be SWT.DEFAULT)
      Returns:
      the preferred size of the control
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • computeSize

      public Point computeSize(int wHint, int hHint, boolean changed)
      Returns the preferred size (in points) of the receiver.

      The preferred size of a control is the size that it would best be displayed at. The width hint and height hint arguments allow the caller to ask a control questions such as "Given a particular width, how high does the control need to be to show all of the contents?" To indicate that the caller does not wish to constrain a particular dimension, the constant SWT.DEFAULT is passed for the hint.

      If the changed flag is true, it indicates that the receiver's contents have changed, therefore any caches that a layout manager containing the control may have been keeping need to be flushed. When the control is resized, the changed flag will be false, so layout manager caches can be retained.

      Parameters:
      wHint - the width hint (can be SWT.DEFAULT)
      hHint - the height hint (can be SWT.DEFAULT)
      changed - true if the control's contents have changed, and false otherwise
      Returns:
      the preferred size of the control.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • dragDetect

      public boolean dragDetect(Event event)
      Detects a drag and drop gesture. This method is used to detect a drag gesture when called from within a mouse down listener.

      By default, a drag is detected when the gesture occurs anywhere within the client area of a control. Some controls, such as tables and trees, override this behavior. In addition to the operating system specific drag gesture, they require the mouse to be inside an item. Custom widget writers can use setDragDetect to disable the default detection, listen for mouse down, and then call dragDetect() from within the listener to conditionally detect a drag.

      Parameters:
      event - the mouse down event
      Returns:
      true if the gesture occurred, and false otherwise.
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT if the event is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
      See Also:
    • dragDetect

      public boolean dragDetect(MouseEvent event)
      Detects a drag and drop gesture. This method is used to detect a drag gesture when called from within a mouse down listener.

      By default, a drag is detected when the gesture occurs anywhere within the client area of a control. Some controls, such as tables and trees, override this behavior. In addition to the operating system specific drag gesture, they require the mouse to be inside an item. Custom widget writers can use setDragDetect to disable the default detection, listen for mouse down, and then call dragDetect() from within the listener to conditionally detect a drag.

      Parameters:
      event - the mouse down event
      Returns:
      true if the gesture occurred, and false otherwise.
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT if the event is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
      See Also:
    • forceFocus

      public boolean forceFocus()
      Forces the receiver to have the keyboard focus, causing all keyboard events to be delivered to it.
      Returns:
      true if the control got focus, and false if it was unable to.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • getAccessible

      public Accessible getAccessible()
      Returns the accessible object for the receiver.

      If this is the first time this object is requested, then the object is created and returned. The object returned by getAccessible() does not need to be disposed.

      Returns:
      the accessible object
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      2.0
      See Also:
    • getBackground

      public Color getBackground()
      Returns the receiver's background color.

      Note: This operation is a hint and may be overridden by the platform. For example, on some versions of Windows the background of a TabFolder, is a gradient rather than a solid color.

      Returns:
      the background color
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getBackgroundImage

      public Image getBackgroundImage()
      Returns the receiver's background image.
      Returns:
      the background image
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.2
    • getBorderWidth

      public int getBorderWidth()
      Returns the receiver's border width in points.
      Returns:
      the border width
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getBounds

      public Rectangle getBounds()
      Returns a rectangle describing the receiver's size and location in points relative to its parent (or its display if its parent is null), unless the receiver is a shell. In this case, the location is relative to the display.
      Returns:
      the receiver's bounding rectangle
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getCursor

      public Cursor getCursor()
      Returns the receiver's cursor, or null if it has not been set.

      When the mouse pointer passes over a control its appearance is changed to match the control's cursor.

      Returns:
      the receiver's cursor or null
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
    • getDragDetect

      public boolean getDragDetect()
      Returns true if the receiver is detecting drag gestures, and false otherwise.
      Returns:
      the receiver's drag detect state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
    • getEnabled

      public boolean getEnabled()
      Returns true if the receiver is enabled, and false otherwise. A disabled control is typically not selectable from the user interface and draws with an inactive or "grayed" look.
      Returns:
      the receiver's enabled state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • getFont

      public Font getFont()
      Returns the font that the receiver will use to paint textual information.
      Returns:
      the receiver's font
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getForeground

      public Color getForeground()
      Returns the foreground color that the receiver will use to draw.
      Returns:
      the receiver's foreground color
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getLayoutData

      public Object getLayoutData()
      Returns layout data which is associated with the receiver.
      Returns:
      the receiver's layout data
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getLocation

      public Point getLocation()
      Returns a point describing the receiver's location relative to its parent in points (or its display if its parent is null), unless the receiver is a shell. In this case, the point is relative to the display.
      Returns:
      the receiver's location
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getMenu

      public Menu getMenu()
      Returns the receiver's pop up menu if it has one, or null if it does not. All controls may optionally have a pop up menu that is displayed when the user requests one for the control. The sequence of key strokes, button presses and/or button releases that are used to request a pop up menu is platform specific.
      Returns:
      the receiver's menu
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getMonitor

      public Monitor getMonitor()
      Returns the receiver's monitor.
      Returns:
      the receiver's monitor
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.0
    • getOrientation

      public int getOrientation()
      Returns the orientation of the receiver, which will be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
      Returns:
      the orientation style
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.7
    • getParent

      public Composite getParent()
      Returns the receiver's parent, which must be a Composite or null when the receiver is a shell that was created with null or a display for a parent.
      Returns:
      the receiver's parent
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getRegion

      public Region getRegion()
      Returns the region that defines the shape of the control, or null if the control has the default shape.
      Returns:
      the region that defines the shape of the shell (or null)
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.4
    • getShell

      public Shell getShell()
      Returns the receiver's shell. For all controls other than shells, this simply returns the control's nearest ancestor shell. Shells return themselves, even if they are children of other shells.
      Returns:
      the receiver's shell
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • getSize

      public Point getSize()
      Returns a point describing the receiver's size in points. The x coordinate of the result is the width of the receiver. The y coordinate of the result is the height of the receiver.
      Returns:
      the receiver's size
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getTextDirection

      public int getTextDirection()
      Returns the text direction of the receiver, which will be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
      Returns:
      the text direction style
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.102
    • getToolTipText

      public String getToolTipText()
      Returns the receiver's tool tip text, or null if it has not been set.
      Returns:
      the receiver's tool tip text
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getTouchEnabled

      public boolean getTouchEnabled()
      Returns true if this control is set to send touch events, or false if it is set to send gesture events instead. This method also returns false if a touch-based input device is not detected (this can be determined with Display#getTouchEnabled()). Use setTouchEnabled(boolean) to switch the events that a control sends between touch events and gesture events.
      Returns:
      true if the control is set to send touch events, or false otherwise
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.7
      See Also:
    • getVisible

      public boolean getVisible()
      Returns true if the receiver is visible, and false otherwise.

      If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, this method may still indicate that it is considered visible even though it may not actually be showing.

      Returns:
      the receiver's visibility state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • internal_new_GC

      public long internal_new_GC(GCData data)
      Invokes platform specific functionality to allocate a new GC handle.

      IMPORTANT: This method is not part of the public API for Control. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.

      Specified by:
      internal_new_GC in interface Drawable
      Parameters:
      data - the platform specific GC data
      Returns:
      the platform specific GC handle
      Restriction:
      This method is not intended to be referenced by clients.
    • internal_dispose_GC

      public void internal_dispose_GC(long hDC, GCData data)
      Invokes platform specific functionality to dispose a GC handle.

      IMPORTANT: This method is not part of the public API for Control. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.

      Specified by:
      internal_dispose_GC in interface Drawable
      Parameters:
      hDC - the platform specific GC handle
      data - the platform specific GC data
      Restriction:
      This method is not intended to be referenced by clients.
    • isEnabled

      public boolean isEnabled()
      Returns true if the receiver is enabled and all ancestors up to and including the receiver's nearest ancestor shell are enabled. Otherwise, false is returned. A disabled control is typically not selectable from the user interface and draws with an inactive or "grayed" look.
      Returns:
      the receiver's enabled state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • isFocusControl

      public boolean isFocusControl()
      Returns true if the receiver has the user-interface focus, and false otherwise.
      Returns:
      the receiver's focus state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • isReparentable

      public boolean isReparentable()
      Returns true if the underlying operating system supports this reparenting, otherwise false
      Returns:
      true if the widget can be reparented, otherwise false
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • isVisible

      public boolean isVisible()
      Returns true if the receiver is visible and all ancestors up to and including the receiver's nearest ancestor shell are visible. Otherwise, false is returned.
      Returns:
      the receiver's visibility state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • moveAbove

      public void moveAbove(Control control)
      Moves the receiver above the specified control in the drawing order. If the argument is null, then the receiver is moved to the top of the drawing order. The control at the top of the drawing order will not be covered by other controls even if they occupy intersecting areas.
      Parameters:
      control - the sibling control (or null)
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the control has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • moveBelow

      public void moveBelow(Control control)
      Moves the receiver below the specified control in the drawing order. If the argument is null, then the receiver is moved to the bottom of the drawing order. The control at the bottom of the drawing order will be covered by all other controls which occupy intersecting areas.
      Parameters:
      control - the sibling control (or null)
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the control has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • pack

      public void pack()
      Causes the receiver to be resized to its preferred size. For a composite, this involves computing the preferred size from its layout, if there is one.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • pack

      public void pack(boolean changed)
      Causes the receiver to be resized to its preferred size. For a composite, this involves computing the preferred size from its layout, if there is one.

      If the changed flag is true, it indicates that the receiver's contents have changed, therefore any caches that a layout manager containing the control may have been keeping need to be flushed. When the control is resized, the changed flag will be false, so layout manager caches can be retained.

      Parameters:
      changed - whether or not the receiver's contents have changed
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • print

      public boolean print(GC gc)
      Prints the receiver and all children.
      Parameters:
      gc - the gc where the drawing occurs
      Returns:
      true if the operation was successful and false otherwise
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the gc is null
      • ERROR_INVALID_ARGUMENT - if the gc has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.4
    • requestLayout

      public void requestLayout()
      Requests that this control and all of its ancestors be repositioned by their layouts at the earliest opportunity. This should be invoked after modifying the control in order to inform any dependent layouts of the change.

      The control will not be repositioned synchronously. This method is fast-running and only marks the control for future participation in a deferred layout.

      Invoking this method multiple times before the layout occurs is an inexpensive no-op.

      Since:
      3.105
    • redraw

      public void redraw()
      Causes the entire bounds of the receiver to be marked as needing to be redrawn. The next time a paint request is processed, the control will be completely painted, including the background.

      Schedules a paint request if the invalidated area is visible or becomes visible later. It is not necessary for the caller to explicitly call update() after calling this method, but depending on the platform, the automatic repaints may be delayed considerably.

      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • redraw

      public void redraw(int x, int y, int width, int height, boolean all)
      Causes the rectangular area of the receiver specified by the arguments to be marked as needing to be redrawn. The next time a paint request is processed, that area of the receiver will be painted, including the background. If the all flag is true, any children of the receiver which intersect with the specified area will also paint their intersecting areas. If the all flag is false, the children will not be painted.

      Schedules a paint request if the invalidated area is visible or becomes visible later. It is not necessary for the caller to explicitly call update() after calling this method, but depending on the platform, the automatic repaints may be delayed considerably.

      Parameters:
      x - the x coordinate of the area to draw
      y - the y coordinate of the area to draw
      width - the width of the area to draw
      height - the height of the area to draw
      all - true if children should redraw, and false otherwise
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeControlListener

      public void removeControlListener(ControlListener listener)
      Removes the listener from the collection of listeners who will be notified when the control is moved or resized.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeDragDetectListener

      public void removeDragDetectListener(DragDetectListener listener)
      Removes the listener from the collection of listeners who will be notified when a drag gesture occurs.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
      See Also:
    • removeFocusListener

      public void removeFocusListener(FocusListener listener)
      Removes the listener from the collection of listeners who will be notified when the control gains or loses focus.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeGestureListener

      public void removeGestureListener(GestureListener listener)
      Removes the listener from the collection of listeners who will be notified when gesture events are generated for the control.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.7
      See Also:
    • removeHelpListener

      public void removeHelpListener(HelpListener listener)
      Removes the listener from the collection of listeners who will be notified when the help events are generated for the control.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeKeyListener

      public void removeKeyListener(KeyListener listener)
      Removes the listener from the collection of listeners who will be notified when keys are pressed and released on the system keyboard.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeMenuDetectListener

      public void removeMenuDetectListener(MenuDetectListener listener)
      Removes the listener from the collection of listeners who will be notified when the platform-specific context menu trigger has occurred.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
      See Also:
    • removeMouseTrackListener

      public void removeMouseTrackListener(MouseTrackListener listener)
      Removes the listener from the collection of listeners who will be notified when the mouse passes or hovers over controls.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeMouseListener

      public void removeMouseListener(MouseListener listener)
      Removes the listener from the collection of listeners who will be notified when mouse buttons are pressed and released.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeMouseMoveListener

      public void removeMouseMoveListener(MouseMoveListener listener)
      Removes the listener from the collection of listeners who will be notified when the mouse moves.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeMouseWheelListener

      public void removeMouseWheelListener(MouseWheelListener listener)
      Removes the listener from the collection of listeners who will be notified when the mouse wheel is scrolled.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
      See Also:
    • removePaintListener

      public void removePaintListener(PaintListener listener)
      Removes the listener from the collection of listeners who will be notified when the receiver needs to be painted.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • removeTouchListener

      public void removeTouchListener(TouchListener listener)
      Removes the listener from the collection of listeners who will be notified when touch events occur.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.7
      See Also:
    • removeTraverseListener

      public void removeTraverseListener(TraverseListener listener)
      Removes the listener from the collection of listeners who will be notified when traversal events occur.
      Parameters:
      listener - the listener which should no longer be notified
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the listener is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • setBackground

      public void setBackground(Color color)
      Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null.

      Note: This operation is a hint and may be overridden by the platform.

      Parameters:
      color - the new color (or null)
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the argument has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setBackgroundImage

      public void setBackgroundImage(Image image)
      Sets the receiver's background image to the image specified by the argument, or to the default system color for the control if the argument is null. The background image is tiled to fill the available space.

      Note: This operation is a hint and may be overridden by the platform. For example, on Windows the background of a Button cannot be changed.

      Parameters:
      image - the new image (or null)
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the argument has been disposed
      • ERROR_INVALID_ARGUMENT - if the argument is not a bitmap
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.2
    • setBounds

      public void setBounds(int x, int y, int width, int height)
      Sets the receiver's size and location in points to the rectangular area specified by the arguments. The x and y arguments are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell. In this case, the x and y arguments are relative to the display.

      Note: Attempting to set the width or height of the receiver to a negative number will cause that value to be set to zero instead.

      Note: On GTK, attempting to set the width or height of the receiver to a number higher or equal 2^14 will cause them to be set to (2^14)-1 instead.

      Parameters:
      x - the new x coordinate for the receiver
      y - the new y coordinate for the receiver
      width - the new width for the receiver
      height - the new height for the receiver
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setBounds

      public void setBounds(Rectangle rect)
      Sets the receiver's size and location in points to the rectangular area specified by the argument. The x and y fields of the rectangle are relative to the receiver's parent (or its display if its parent is null).

      Note: Attempting to set the width or height of the receiver to a negative number will cause that value to be set to zero instead.

      Note: On GTK, attempting to set the width or height of the receiver to a number higher or equal 2^14 will cause them to be set to (2^14)-1 instead.

      Parameters:
      rect - the new bounds for the receiver
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setCapture

      public void setCapture(boolean capture)
      If the argument is true, causes the receiver to have all mouse events delivered to it until the method is called with false as the argument. Note that on some platforms, a mouse button must currently be down for capture to be assigned.
      Parameters:
      capture - true to capture the mouse, and false to release it
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setCursor

      public void setCursor(Cursor cursor)
      Sets the receiver's cursor to the cursor specified by the argument, or to the default cursor for that kind of control if the argument is null.

      When the mouse pointer passes over a control its appearance is changed to match the control's cursor.

      Parameters:
      cursor - the new cursor (or null)
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the argument has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setDragDetect

      public void setDragDetect(boolean dragDetect)
      Sets the receiver's drag detect state. If the argument is true, the receiver will detect drag gestures, otherwise these gestures will be ignored.
      Parameters:
      dragDetect - the new drag detect state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.3
    • setEnabled

      public void setEnabled(boolean enabled)
      Enables the receiver if the argument is true, and disables it otherwise. A disabled control is typically not selectable from the user interface and draws with an inactive or "grayed" look.
      Parameters:
      enabled - the new enabled state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setFocus

      public boolean setFocus()
      Causes the receiver to have the keyboard focus, such that all keyboard events will be delivered to it. Focus reassignment will respect applicable platform constraints.
      Returns:
      true if the control got focus, and false if it was unable to.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • setFont

      public void setFont(Font font)
      Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.
      Parameters:
      font - the new font (or null)
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the argument has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setForeground

      public void setForeground(Color color)
      Sets the receiver's foreground color to the color specified by the argument, or to the default system color for the control if the argument is null.

      Note: This operation is a hint and may be overridden by the platform.

      Parameters:
      color - the new color (or null)
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the argument has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setLayoutData

      public void setLayoutData(Object layoutData)
      Sets the layout data associated with the receiver to the argument.
      Parameters:
      layoutData - the new layout data for the receiver.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setLocation

      public void setLocation(int x, int y)
      Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell. In this case, the point is relative to the display.
      Parameters:
      x - the new x coordinate for the receiver
      y - the new y coordinate for the receiver
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setLocation

      public void setLocation(Point location)
      Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell. In this case, the point is relative to the display.
      Parameters:
      location - the new location for the receiver
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setMenu

      public void setMenu(Menu menu)
      Sets the receiver's pop up menu to the argument. All controls may optionally have a pop up menu that is displayed when the user requests one for the control. The sequence of key strokes, button presses and/or button releases that are used to request a pop up menu is platform specific.

      Note: Disposing of a control that has a pop up menu will dispose of the menu. To avoid this behavior, set the menu to null before the control is disposed.

      Parameters:
      menu - the new pop up menu
      Throws:
      IllegalArgumentException -
      • ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu
      • ERROR_INVALID_PARENT - if the menu is not in the same widget tree
      • ERROR_INVALID_ARGUMENT - if the menu has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setOrientation

      public void setOrientation(int orientation)
      Sets the orientation of the receiver, which must be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
      Parameters:
      orientation - new orientation style
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.7
    • setRedraw

      public void setRedraw(boolean redraw)
      If the argument is false, causes subsequent drawing operations in the receiver to be ignored. No drawing of any kind can occur in the receiver until the flag is set to true. Graphics operations that occurred while the flag was false are lost. When the flag is set to true, the entire widget is marked as needing to be redrawn. Nested calls to this method are stacked.

      Note: This operation is a hint and may not be supported on some platforms or for some widgets.

      Parameters:
      redraw - the new redraw state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • setRegion

      public void setRegion(Region region)
      Sets the shape of the control to the region specified by the argument. When the argument is null, the default shape of the control is restored.
      Parameters:
      region - the region that defines the shape of the control (or null)
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the region has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.4
    • setSize

      public void setSize(int width, int height)
      Sets the receiver's size to the point specified by the arguments.

      Note: Attempting to set the width or height of the receiver to a negative number will cause that value to be set to zero instead.

      Note: On GTK, attempting to set the width or height of the receiver to a number higher or equal 2^14 will cause them to be set to (2^14)-1 instead.

      Parameters:
      width - the new width in points for the receiver
      height - the new height in points for the receiver
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setSize

      public void setSize(Point size)
      Sets the receiver's size to the point specified by the argument.

      Note: Attempting to set the width or height of the receiver to a negative number will cause them to be set to zero instead.

      Note: On GTK, attempting to set the width or height of the receiver to a number higher or equal 2^14 will cause them to be set to (2^14)-1 instead.

      Parameters:
      size - the new size in points for the receiver
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the point is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setTextDirection

      public void setTextDirection(int textDirection)
      Sets the base text direction (a.k.a. "paragraph direction") of the receiver, which must be one of the constants SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, or SWT.AUTO_TEXT_DIRECTION.

      setOrientation would override this value with the text direction that is consistent with the new orientation.

      Warning: This API is currently only implemented on Windows. It doesn't set the base text direction on GTK and Cocoa.

      Parameters:
      textDirection - the base text direction style
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.102
      See Also:
    • setToolTipText

      public void setToolTipText(String string)
      Sets the receiver's tool tip text to the argument, which may be null indicating that the default tool tip for the control will be shown. For a control that has a default tool tip, such as the Tree control on Windows, setting the tool tip text to an empty string replaces the default, causing no tool tip text to be shown.

      The mnemonic indicator (character '&') is not displayed in a tool tip. To display a single '&' in the tool tip, the character '&' can be escaped by doubling it in the string.

      NOTE: This operation is a hint and behavior is platform specific, on Windows for CJK-style mnemonics of the form " (&C)" at the end of the tooltip text are not shown in tooltip.

      Parameters:
      string - the new tool tip text (or null)
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setTouchEnabled

      public void setTouchEnabled(boolean enabled)
      Sets whether this control should send touch events (by default controls do not). Setting this to false causes the receiver to send gesture events instead. No exception is thrown if a touch-based input device is not detected (this can be determined with Display#getTouchEnabled()).
      Parameters:
      enabled - the new touch-enabled state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.7
      See Also:
    • setVisible

      public void setVisible(boolean visible)
      Marks the receiver as visible if the argument is true, and marks it invisible otherwise.

      If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking it visible may not actually cause it to be displayed.

      Parameters:
      visible - the new visibility state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • toControl

      public Point toControl(int x, int y)
      Returns a point which is the result of converting the argument, which is specified in display relative coordinates, to coordinates relative to the receiver.

      NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use Display.map(Control, Control, Rectangle).

      Parameters:
      x - the x coordinate in points to be translated
      y - the y coordinate in points to be translated
      Returns:
      the translated coordinates
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      2.1
    • toControl

      public Point toControl(Point point)
      Returns a point which is the result of converting the argument, which is specified in display relative coordinates, to coordinates relative to the receiver.

      NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use Display.map(Control, Control, Rectangle).

      Parameters:
      point - the point to be translated (must not be null)
      Returns:
      the translated coordinates
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the point is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • toDisplay

      public Point toDisplay(int x, int y)
      Returns a point which is the result of converting the argument, which is specified in coordinates relative to the receiver, to display relative coordinates.

      NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use Display.map(Control, Control, Rectangle).

      Parameters:
      x - the x coordinate to be translated
      y - the y coordinate to be translated
      Returns:
      the translated coordinates
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      2.1
    • toDisplay

      public Point toDisplay(Point point)
      Returns a point which is the result of converting the argument, which is specified in coordinates relative to the receiver, to display relative coordinates.

      NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use Display.map(Control, Control, Rectangle).

      Parameters:
      point - the point to be translated (must not be null)
      Returns:
      the translated coordinates
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the point is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • traverse

      public boolean traverse(int traversal)
      Based on the argument, perform one of the expected platform traversal action. The argument should be one of the constants: SWT.TRAVERSE_ESCAPE, SWT.TRAVERSE_RETURN, SWT.TRAVERSE_TAB_NEXT, SWT.TRAVERSE_TAB_PREVIOUS, SWT.TRAVERSE_ARROW_NEXT, SWT.TRAVERSE_ARROW_PREVIOUS, SWT.TRAVERSE_PAGE_NEXT and SWT.TRAVERSE_PAGE_PREVIOUS.
      Parameters:
      traversal - the type of traversal
      Returns:
      true if the traversal succeeded
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • traverse

      public boolean traverse(int traversal, Event event)
      Performs a platform traversal action corresponding to a KeyDown event.

      Valid traversal values are SWT.TRAVERSE_NONE, SWT.TRAVERSE_MNEMONIC, SWT.TRAVERSE_ESCAPE, SWT.TRAVERSE_RETURN, SWT.TRAVERSE_TAB_NEXT, SWT.TRAVERSE_TAB_PREVIOUS, SWT.TRAVERSE_ARROW_NEXT, SWT.TRAVERSE_ARROW_PREVIOUS, SWT.TRAVERSE_PAGE_NEXT and SWT.TRAVERSE_PAGE_PREVIOUS. If traversal is SWT.TRAVERSE_NONE then the Traverse event is created with standard values based on the KeyDown event. If traversal is one of the other traversal constants then the Traverse event is created with this detail, and its doit is taken from the KeyDown event.

      Parameters:
      traversal - the type of traversal, or SWT.TRAVERSE_NONE to compute this from event
      event - the KeyDown event
      Returns:
      true if the traversal succeeded
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT if the event is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.6
    • traverse

      public boolean traverse(int traversal, KeyEvent event)
      Performs a platform traversal action corresponding to a KeyDown event.

      Valid traversal values are SWT.TRAVERSE_NONE, SWT.TRAVERSE_MNEMONIC, SWT.TRAVERSE_ESCAPE, SWT.TRAVERSE_RETURN, SWT.TRAVERSE_TAB_NEXT, SWT.TRAVERSE_TAB_PREVIOUS, SWT.TRAVERSE_ARROW_NEXT, SWT.TRAVERSE_ARROW_PREVIOUS, SWT.TRAVERSE_PAGE_NEXT and SWT.TRAVERSE_PAGE_PREVIOUS. If traversal is SWT.TRAVERSE_NONE then the Traverse event is created with standard values based on the KeyDown event. If traversal is one of the other traversal constants then the Traverse event is created with this detail, and its doit is taken from the KeyDown event.

      Parameters:
      traversal - the type of traversal, or SWT.TRAVERSE_NONE to compute this from event
      event - the KeyDown event
      Returns:
      true if the traversal succeeded
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT if the event is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.6
    • update

      public void update()
      Forces all outstanding paint requests for the widget to be processed before this method returns. If there are no outstanding paint request, this method does nothing.

      Note:

      • This method does not cause a redraw.
      • Some OS versions forcefully perform automatic deferred painting. This method does nothing in that case.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
    • setParent

      public boolean setParent(Composite parent)
      Changes the parent of the widget to be the one provided. Returns true if the parent is successfully changed.
      Parameters:
      parent - the new parent for the control.
      Returns:
      true if the parent is changed and false otherwise.
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the argument has been disposed
      • ERROR_NULL_ARGUMENT - if the parent is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver