Eclipse Platform
2.0

org.eclipse.swt.widgets
Class Control

java.lang.Object
  |
  +--org.eclipse.swt.widgets.Widget
        |
        +--org.eclipse.swt.widgets.Control
All Implemented Interfaces:
Drawable
Direct Known Subclasses:
Button, Label, 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
Events:
FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter, MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize

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


Field Summary
 int handle
          the handle to the OS resource (Warning: This field is platform dependent)
 
Constructor Summary
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
 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.
 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.
 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.
 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.
 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.
 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.
 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.
 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.
 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.
 Point computeSize(int wHint, int hHint)
          Returns the preferred size of the receiver.
 Point computeSize(int wHint, int hHint, boolean changed)
          Returns the preferred size of the receiver.
 boolean forceFocus()
          Forces the receiver to have the keyboard focus, causing all keyboard events to be delivered to it.
 Accessible getAccessible()
          Returns the accessible object for the receiver.
 Color getBackground()
          Returns the receiver's background color.
 int getBorderWidth()
          Returns the receiver's border width.
 Rectangle getBounds()
          Returns a rectangle describing the receiver's size and location relative to its parent (or its display if its parent is null).
 Display getDisplay()
          Returns the display that the receiver was created on.
 boolean getEnabled()
          Returns true if the receiver is enabled, and false otherwise.
 Font getFont()
          Returns the font that the receiver will use to paint textual information.
 Color getForeground()
          Returns the foreground color that the receiver will use to draw.
 Object getLayoutData()
          Returns layout data which is associated with the receiver.
 Point getLocation()
          Returns a point describing the receiver's location relative to its parent (or its display if its parent is null).
 Menu getMenu()
          Returns the receiver's pop up menu if it has one, or null if it does not.
 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.
 Shell getShell()
          Returns the receiver's shell.
 Point getSize()
          Returns a point describing the receiver's size.
 String getToolTipText()
          Returns the receiver's tool tip text, or null if it has not been set.
 boolean getVisible()
          Returns true if the receiver is visible, and false otherwise.
 void internal_dispose_GC(int hDC, GCData data)
          Invokes platform specific functionality to dispose a GC handle.
 int internal_new_GC(GCData data)
          Invokes platform specific functionality to allocate a new GC handle.
 boolean isDisposed()
          Returns true if the widget has been disposed, and false otherwise.
 boolean isEnabled()
          Returns true if the receiver is enabled and all of the receiver's ancestors are enabled, and false otherwise.
 boolean isFocusControl()
          Returns true if the receiver has the user-interface focus, and false otherwise.
 boolean isReparentable()
          Returns true if the underlying operating system supports this reparenting, otherwise false
 boolean isVisible()
          Returns true if the receiver is visible and all of the receiver's ancestors are visible and false otherwise.
 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 pack()
          Causes the receiver to be resized to its preferred size.
 void pack(boolean changed)
          Causes the receiver to be resized to its preferred size.
 void redraw()
          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 removeControlListener(ControlListener listener)
          Removes the listener from the collection of listeners who will be notified when the control is moved or resized.
 void removeFocusListener(FocusListener listener)
          Removes the listener from the collection of listeners who will be notified when the control gains or loses focus.
 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.
 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.
 void removeMouseListener(MouseListener listener)
          Removes the listener from the collection of listeners who will be notified when mouse buttons are pressed and released.
 void removeMouseMoveListener(MouseMoveListener listener)
          Removes the listener from the collection of listeners who will be notified when the mouse moves.
 void removeMouseTrackListener(MouseTrackListener listener)
          Removes the listener from the collection of listeners who will be notified when the mouse passes or hovers over controls.
 void removePaintListener(PaintListener listener)
          Removes the listener from the collection of listeners who will be notified when the receiver needs to be painted.
 void removeTraverseListener(TraverseListener listener)
          Removes the listener from the collection of listeners who will be notified when traversal events occur.
 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.
 void setBounds(int x, int y, int width, int height)
          Sets the receiver's size and location to the rectangular area specified by the arguments.
 void setBounds(Rectangle rect)
          Sets the receiver's size and location 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 setEnabled(boolean enabled)
          Enables the receiver if the argument is true, and disables it otherwise.
 boolean setFocus()
          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 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.
 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).
 void setLocation(Point location)
          Sets the receiver's location to the point specified by the argument which is relative to the receiver's parent (or its display if its parent is null).
 void setMenu(Menu menu)
          Sets the receiver's pop up menu to the argument.
 boolean setParent(Composite parent)
          Changes the parent of the widget to be the one provided if the underlying operating system supports this feature.
 void setRedraw(boolean redraw)
          If the argument is false, causes subsequent drawing operations in the receiver to be ignored.
 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 setToolTipText(String string)
          Sets the receiver's tool tip text to the argument, which may be null indicating that no tool tip text should be shown.
 void setVisible(boolean visible)
          Marks the receiver as visible if the argument is true, and marks it invisible otherwise.
 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.
 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.
 boolean traverse(int traversal)
          Based on the argument, perform one of the expected platform traversal action.
 void update()
          Forces all outstanding paint requests for the widget tree to be processed before this method returns.
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getStyle, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

handle

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

Constructor Detail

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 -
SWTException -
See Also:
SWT.BORDER, Widget.checkSubclass(), Widget.getStyle()
Method Detail

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:
ControlListener, removeControlListener(org.eclipse.swt.events.ControlListener)

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:
FocusListener, removeFocusListener(org.eclipse.swt.events.FocusListener)

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:
HelpListener, removeHelpListener(org.eclipse.swt.events.HelpListener)

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.

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:
KeyListener, removeKeyListener(org.eclipse.swt.events.KeyListener)

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:
MouseListener, removeMouseListener(org.eclipse.swt.events.MouseListener)

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:
MouseTrackListener, removeMouseTrackListener(org.eclipse.swt.events.MouseTrackListener)

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:
MouseMoveListener, removeMouseMoveListener(org.eclipse.swt.events.MouseMoveListener)

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:
PaintListener, removePaintListener(org.eclipse.swt.events.PaintListener)

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:
TraverseListener, removeTraverseListener(org.eclipse.swt.events.TraverseListener)

computeSize

public Point computeSize(int wHint,
                         int hHint)
Returns the preferred size 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:
Layout, getBorderWidth(), getBounds(), getSize(), pack(), "computeTrim, getClientArea for controls that implement them"

computeSize

public Point computeSize(int wHint,
                         int hHint,
                         boolean changed)
Returns the preferred size 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:
Layout, getBorderWidth(), getBounds(), getSize(), pack(), "computeTrim, getClientArea for controls that implement them"

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:
setFocus()

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.

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:
Accessible.addAccessibleListener(org.eclipse.swt.accessibility.AccessibleListener), Accessible.addAccessibleControlListener(org.eclipse.swt.accessibility.AccessibleControlListener)

getBackground

public Color getBackground()
Returns the receiver's background 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

getBorderWidth

public int getBorderWidth()
Returns the receiver's border width.

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 relative to its parent (or its display if its parent is null).

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

getDisplay

public Display getDisplay()
Returns the display that the receiver was created on.

Specified by:
getDisplay in class Widget
Returns:
the receiver's display
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

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:
isEnabled()

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 (or its display if its parent is null).

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

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

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:
getParent()

getSize

public Point getSize()
Returns a point describing the receiver's size. 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

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

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 int 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

internal_dispose_GC

public void internal_dispose_GC(int 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:
data - the platform specific GC data
hDC - the platform specific GC handle

isDisposed

public boolean isDisposed()
Description copied from class: Widget
Returns true if the widget has been disposed, and false otherwise.

This method gets the dispose state for the widget. When a widget has been disposed, it is an error to invoke any other method using the widget.

Overrides:
isDisposed in class Widget
Returns:
true when the widget is disposed and false otherwise

isEnabled

public boolean isEnabled()
Returns true if the receiver is enabled and all of the receiver's ancestors are 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:
getEnabled()

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 of the receiver's ancestors are visible and false otherwise.

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:
getVisible()

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.

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

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.

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

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:
computeSize(int, int)

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.

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(int, int)

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.

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:
update()

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. 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.

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:
update()

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 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:
ControlListener, addControlListener(org.eclipse.swt.events.ControlListener)

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 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:
FocusListener, addFocusListener(org.eclipse.swt.events.FocusListener)

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 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:
HelpListener, addHelpListener(org.eclipse.swt.events.HelpListener)

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 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:
KeyListener, addKeyListener(org.eclipse.swt.events.KeyListener)

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 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:
MouseTrackListener, addMouseTrackListener(org.eclipse.swt.events.MouseTrackListener)

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 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:
MouseListener, addMouseListener(org.eclipse.swt.events.MouseListener)

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 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:
MouseMoveListener, addMouseMoveListener(org.eclipse.swt.events.MouseMoveListener)

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 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:
PaintListener, addPaintListener(org.eclipse.swt.events.PaintListener)

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 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:
TraverseListener, addTraverseListener(org.eclipse.swt.events.TraverseListener)

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.

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

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Sets the receiver's size and location 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).

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.

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 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.

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.

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

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.

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:
forceFocus()

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.

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).

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 argument which is relative to the receiver's parent (or its display if its parent is null).

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.

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

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.

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:
redraw(), update()

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.

Parameters:
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

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.

Parameters:
size - the new size 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

setToolTipText

public void setToolTipText(String string)
Sets the receiver's tool tip text to the argument, which may be null indicating that no tool tip text should be shown.

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

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(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.

Parameters:
point - the point to be translated (must not be null)
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(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.

Parameters:
point - the point to be translated (must not be null)
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 and SWT.TRAVERSE_ARROW_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

update

public void update()
Forces all outstanding paint requests for the widget tree to be processed before this method returns.

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()

setParent

public boolean setParent(Composite parent)
Changes the parent of the widget to be the one provided if the underlying operating system supports this feature. Answers 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
SWTError -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed

Eclipse Platform
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.