org.eclipse.swt.widgets
Class Control

java.lang.Object
  |
  +--org.eclipse.swt.widgets.Widget
        |
        +--org.eclipse.swt.widgets.Control
All Implemented Interfaces:
Drawable, Runnable
Direct Known Subclasses:
Button, Label, Scrollable

public class Control
extends Widget
implements Drawable


Field Summary
 
Fields inherited from class org.eclipse.swt.widgets.Widget
h, INCMD_DISPOSE, INCMD_EXTKEY, INCMD_KEY, INCMD_LDOWN, INCMD_LUP, INCMD_MENU, INCMD_POS, UPDATEITEM_ENABLED, UPDATEITEM_NAME, w, x, y
 
Constructor Summary
protected Control()
          Prevents uninitialized instances from being created outside the package.
 
Method Summary
 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.
 Object getLayoutData()
          Returns layout data which is associated with the receiver.
 boolean isFocusControl()
          Returns true if the receiver has the user-interface focus, and false otherwise.
 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 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(Rectangle rect)
          Sets the receiver's size and location to the rectangular area specified by the argument.
 boolean setFocus()
          Set the input focus to the widget, and returns whether the focus change was successful.
 void setLayoutData(Object layoutData)
          Sets the layout data associated with the receiver to 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 update()
          Forces all outstanding paint requests for the widget to be processed before this method returns.
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addListener, dispose, focusState, getBorderWidth, getDisplayArea, getSelection, getStyle, getText, isDisposed, removeListener, setBounds, setCursor, stop
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, toString
 
Methods inherited from interface org.eclipse.swt.graphics.Drawable
drawLine, drawRect, drawText, setColor
 
Methods inherited from interface java.lang.Runnable
run
 

Constructor Detail

Control

protected Control()
Prevents uninitialized instances from being created outside the package.

Method Detail

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

Overrides:
computeSize in class Widget
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, Widget.getBorderWidth(), #getBounds, #getSize, pack(), "computeTrim, getClientArea for controls that implement them"

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

isFocusControl

public boolean isFocusControl()
Returns true if the receiver has the user-interface focus, and false otherwise.

Returns:
the receiver's focus state

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)

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

setFocus

public boolean setFocus()
Set the input focus to the widget, and returns whether the focus change was successful.

Returns:
true if the input focus could be handed over to 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

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

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

update

public void update()
Forces all outstanding paint requests for the widget 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