Class Widget
- Direct Known Subclasses:
Caret
,Control
,DragSource
,DropTarget
,IME
,Item
,Menu
,ScrollBar
,TaskBar
,ToolTip
,Tracker
,Tray
- Styles:
- (none)
- Events:
- Dispose
IMPORTANT: This class is intended to be subclassed only within the SWT implementation. However, it has not been marked final to allow those outside of the SWT development team to implement patched versions of the class in order to get around specific limitations in advance of when those limitations can be addressed by the team. Any class built using subclassing to access the internals of this class will likely fail to compile or run between releases and may be strongly platform specific. Subclassing should not be attempted without an intimate and detailed understanding of the workings of the hierarchy. No support is provided for user-written classes which are implemented as subclasses of this class.
-
Field Summary
Modifier and TypeFieldDescriptionint
the native zoom of the monitor in percent (Warning: This field is platform dependent) -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDisposeListener
(DisposeListener listener) Adds the listener to the collection of listeners who will be notified when the widget is disposed.void
addListener
(int eventType, Listener listener) Adds the listener to the collection oflisteners
who will be notified when an event of the given type occurs.protected void
addTypedListener
(EventListener listener, int... eventTypes) Adds thetyped listener
to the collection of listeners who will be notified when an event of the given types occurs.protected void
Checks that this class can be subclassed.protected void
Throws anSWTException
if the receiver can not be accessed by the caller.void
dispose()
Disposes of the operating system resources associated with the receiver and all its descendants.getData()
Returns the application defined widget data associated with the receiver, or null if it has not been set.Returns the application defined property of the receiver with the specified name, or null if it has not been set.Returns theDisplay
that is associated with the receiver.Listener[]
getListeners
(int eventType) Returns an array oflisteners
who will be notified when an event of the given type occurs.int
getStyle()
Returns the receiver's style information.<L extends EventListener>
Stream<L>getTypedListeners
(int eventType, Class<L> listenerType) Returns the typed listeners who will be notified when an event of the given type occurs.boolean
Returnstrue
if the widget has auto text direction, andfalse
otherwise.boolean
Returnstrue
if the widget has been disposed, andfalse
otherwise.boolean
isListening
(int eventType) Returnstrue
if there are any listeners for the specified event type associated with the receiver, andfalse
otherwise.void
notifyListeners
(int eventType, Event event) Notifies all of the receiver's listeners for events of the given type that one such event has occurred by invoking theirhandleEvent()
method.void
removeDisposeListener
(DisposeListener listener) Removes the listener from the collection of listeners who will be notified when the widget is disposed.protected void
removeListener
(int eventType, SWTEventListener listener) Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.void
removeListener
(int eventType, Listener listener) Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.protected void
removeTypedListener
(int eventType, EventListener listener) Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.void
reskin
(int flags) Marks the widget to be skinned.void
Sets the application defined widget data associated with the receiver to be the argument.void
Sets the application defined property of the receiver with the specified name to the given value.toString()
Returns a string containing a concise, human-readable description of the receiver.
-
Field Details
-
nativeZoom
public int nativeZoomthe native zoom of the monitor in percent (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
-
Widget
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 theint
"|" operator) two or more of thoseSWT
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 widget which will be the parent of the new instance (cannot be null)style
- the style of widget to construct- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
- ERROR_INVALID_ARGUMENT - if the parent is disposed
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
-
addListener
Adds the listener to the collection oflisteners
who will be notified when an event of the given type occurs. When the event does occur in the widget, the listener is notified by sending it thehandleEvent()
message. The event type is one of the event constants defined in classSWT
.- Parameters:
eventType
- the type of event to listen forlistener
- the listener which should be notified when the event occurs- 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:
-
addTypedListener
Adds thetyped listener
to the collection of listeners who will be notified when an event of the given types occurs. When the event does occur in the widget, the listener is notified by calling the type's handling methods. The event type is one of the event constants defined in classSWT
and must correspond to the listeners type. If for example aSelectionListener
is passed theeventTypes
can beSWT.Selection
orSWT.DefaultSelection
.- Parameters:
listener
- the listener which should be notified when the event occurseventTypes
- the types of event to listen for- 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.126
- See Also:
-
addDisposeListener
Adds the listener to the collection of listeners who will be notified when the widget is disposed. When the widget is disposed, the listener is notified by sending it thewidgetDisposed()
message.- Parameters:
listener
- the listener which should be notified when the receiver is disposed- 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:
-
checkSubclass
protected void checkSubclass()Checks that this class can be subclassed.The SWT class library is intended to be subclassed only at specific, controlled points (most notably,
Composite
andCanvas
when implementing new widgets). This method enforces this rule unless it is overridden.IMPORTANT: By providing an implementation of this method that allows a subclass of a class which does not normally allow subclassing to be created, the implementer agrees to be fully responsible for the fact that any such subclass will likely fail between SWT releases and will be strongly platform specific. No support is provided for user-written classes which are implemented in this fashion.
The ability to subclass outside of the allowed SWT classes is intended purely to enable those not on the SWT development team to implement patches in order to get around specific limitations in advance of when those limitations can be addressed by the team. Subclassing should not be attempted without an intimate and detailed understanding of the hierarchy.
- Throws:
SWTException
-- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
-
checkWidget
protected void checkWidget()Throws anSWTException
if the receiver can not be accessed by the caller. This may include both checks on the state of the receiver and more generally on the entire execution context. This method should be called by widget implementors to enforce the standard SWT invariants.Currently, it is an error to invoke any method (other than
isDisposed()
) on a widget that has had itsdispose()
method called. It is also an error to call widget methods from any thread that is different from the thread that created the widget.In future releases of SWT, there may be more or fewer error checks and exceptions may be thrown for different reasons.
- 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
-
dispose
public void dispose()Disposes of the operating system resources associated with the receiver and all its descendants. After this method has been invoked, the receiver and all descendants will answertrue
when sent the messageisDisposed()
. Any internal connections between the widgets in the tree will have been removed to facilitate garbage collection. This method does nothing if the widget is already disposed.NOTE: This method is not called recursively on the descendants of the receiver. This means that, widget implementers can not detect when a widget is being disposed of by re-implementing this method, but should instead listen for the
Dispose
event.- Throws:
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getData
Returns the application defined widget data associated with the receiver, or null if it has not been set. The widget data is a single, unnamed field that is stored with every widget.Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
- Returns:
- the widget data
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - when the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread
- See Also:
-
getData
Returns the application defined property of the receiver with the specified name, or null if it has not been set.Applications may have associated arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
- Parameters:
key
- the name of the property- Returns:
- the value of the property or null if it has not been set
- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the key 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:
-
getDisplay
Returns theDisplay
that is associated with the receiver.A widget's display is either provided when it is created (for example, top level
Shell
s) or is the same as its parent's display.- Returns:
- the receiver's display
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
-
getListeners
Returns an array oflisteners
who will be notified when an event of the given type occurs. The event type is one of the event constants defined in classSWT
.- Parameters:
eventType
- the type of event to listen for- Returns:
- an array of listeners that will be notified when the event occurs
- 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
- See Also:
-
getTypedListeners
Returns the typed listeners who will be notified when an event of the given type occurs. The event type is one of the event constants defined in classSWT
and the specified listener-type must correspond to that event. If for example theeventType
isSWT.Selection
, the listeners type should beSelectionListener
.- Parameters:
eventType
- the type of event to listen for- Returns:
- a stream of typed listeners that will be notified when the event occurs
- 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.126
- See Also:
-
getStyle
public int getStyle()Returns the receiver's style information.Note that the value which is returned by this method may not match the value which was provided to the constructor when the receiver was created. This can occur when the underlying operating system does not support a particular combination of requested styles. For example, if the platform widget used to implement a particular SWT widget always has scroll bars, the result of calling this method would always have the
SWT.H_SCROLL
andSWT.V_SCROLL
bits set.- Returns:
- the style bits
- 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
-
isAutoDirection
public boolean isAutoDirection()Returnstrue
if the widget has auto text direction, andfalse
otherwise.- Returns:
true
when the widget has auto direction andfalse
otherwise- Since:
- 3.105
- See Also:
-
isDisposed
public boolean isDisposed()Returnstrue
if the widget has been disposed, andfalse
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 (except
dispose()
) using the widget.- Returns:
true
when the widget is disposed andfalse
otherwise
-
isListening
public boolean isListening(int eventType) Returnstrue
if there are any listeners for the specified event type associated with the receiver, andfalse
otherwise. The event type is one of the event constants defined in classSWT
.- Parameters:
eventType
- the type of event- Returns:
- true if the event is hooked
- 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:
-
notifyListeners
Notifies all of the receiver's listeners for events of the given type that one such event has occurred by invoking theirhandleEvent()
method. The event type is one of the event constants defined in classSWT
.- Parameters:
eventType
- the type of event which has occurredevent
- the event 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
- See Also:
-
removeListener
Removes the listener from the collection of listeners who will be notified when an event of the given type occurs. The event type is one of the event constants defined in classSWT
.- Parameters:
eventType
- the type of event to listen forlistener
- 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:
-
removeListener
Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.IMPORTANT: This method 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 should never be referenced from application code.
- Parameters:
eventType
- the type of event to listen forlistener
- 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:
- Restriction:
- This method is not intended to be referenced by clients.
- Restriction:
- This method is not intended to be re-implemented or extended by clients.
-
removeTypedListener
Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.IMPORTANT: This method 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 should never be referenced from application code.
- Parameters:
eventType
- the type of event to listen forlistener
- 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:
- Restriction:
- This method is not intended to be referenced by clients.
- Restriction:
- This method is not intended to be re-implemented or extended by clients.
-
removeDisposeListener
Removes the listener from the collection of listeners who will be notified when the widget is disposed.- 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:
-
reskin
public void reskin(int flags) Marks the widget to be skinned.The skin event is sent to the receiver's display when appropriate (usually before the next event is handled). Widgets are automatically marked for skinning upon creation as well as when its skin id or class changes. The skin id and/or class can be changed by calling
Display.setData(String, Object)
with the keysSWT.SKIN_ID
and/orSWT.SKIN_CLASS
. Once the skin event is sent to a widget, it will not be sent again unlessreskin(int)
is called on the widget or on an ancestor while specifying theSWT.ALL
flag.The parameter
flags
may be either:- Parameters:
flags
- the flags specifying how to reskin- 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.6
-
setData
Sets the application defined widget data associated with the receiver to be the argument. The widget data is a single, unnamed field that is stored with every widget.Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
- Parameters:
data
- the widget data- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - when the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread
- See Also:
-
setData
Sets the application defined property of the receiver with the specified name to the given value.Applications may associate arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
- Parameters:
key
- the name of the propertyvalue
- the new value for the property- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the key 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:
-
toString
Returns a string containing a concise, human-readable description of the receiver.
-