Top Description Fields Constructors Methods
org.eclipse.swt.widgets

public Class Event

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.swt.custom.StyledTextEvent, org.eclipse.swt.dnd.DNDEvent
Imports
org.eclipse.swt.graphics.*, org.eclipse.swt.internal.*

Instances of this class provide a description of a particular event which occurred within SWT. The SWT untyped listener API uses these instances for all event dispatching.

Note

For a given event, only the fields which are appropriate will be filled in. The contents of the fields which are not used by the event are unspecified.

See Also
Listener, org.eclipse.swt.events.TypedEvent, SWT Example: ControlExample, Listeners, Sample code and further information

Field Summary

Modifier and TypeField and Description
public int
button

the button that was pressed or released; 1 for the first button, 2 for the second button, and 3 for the third button, etc.

public char
character

depending on the event, the character represented by the key that was typed.

public int
count

depending on the event type, the number of following paint events that are pending which may always be zero on some platforms, or the number of lines or pages to scroll using the mouse wheel, or the number of times the mouse has been clicked

public Object
data

a field for application use

public int
detail

the event specific detail field, as defined by the detail constants in class SWT

public Display
display

the display where the event occurred

public boolean
doit

depending on the event, a flag indicating whether the operation should be allowed.

public int
end

depending on the event, the range of text being modified.

public GC
gc

the graphics context to use when painting that is configured to use the colors, font and damaged region of the control.

public int
height

the height of the bounding rectangle of the region that requires painting

public int
index

the index of the item where the event occurred

public Widget
item

the item that the event occurred in (can be null)

public int
keyCode

character that is good for keyboard shortcut comparison.

public int
keyLocation

depending on the event, the location of key specified by the keyCode or character.

public double
magnification

The change in magnification.

public double
rotation

The number of degrees rotated on the track pad.

public int[]
segments

Bidi segment offsets

public char[]
segmentsChars

Characters to be applied on the segment boundaries

public int
start

depending on the event, the range of text being modified.

public int
stateMask

depending on the event, the state of the keyboard modifier keys and mouse masks at the time the event was generated.

public String
text

depending on the event, the new text that will be inserted.

public int
time

the time that the event occurred.

public Touch[]
touches

An array of the touch states for the current touch event.

public int
type

the type of event, as defined by the event type constants in class SWT

public Widget
widget

the widget that issued the event

public int
width

the width of the bounding rectangle of the region that requires painting

public int
x

depending on the event type, the x offset of the bounding rectangle of the region that requires painting or the widget-relative, x coordinate of the pointer at the time the mouse button was pressed or released

public int
xDirection

If nonzero, a positive value indicates a swipe to the right, and a negative value indicates a swipe to the left.

public int
y

depending on the event type, the y offset of the bounding rectangle of the region that requires painting or the widget-relative, y coordinate of the pointer at the time the mouse button was pressed or released

public int
yDirection

If nonzero, a positive value indicates a swipe in the up direction, and a negative value indicates a swipe in the down direction.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Rectangle

Returns:

a rectangle that is the bounds.
getBounds
()

Gets the bounds.

pack-priv Rectangle
pack-priv Point
pack-priv Point
public void
setBounds(Rectangle
the new rectangle
rect
)

Sets the bounds.

pack-priv void
pack-priv void
setLocationInPixels(int x, int y)

public String

Returns:

a string representation of the event
toString
()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

buttonback to summary
public int button

the button that was pressed or released; 1 for the first button, 2 for the second button, and 3 for the third button, etc.

characterback to summary
public char character

depending on the event, the character represented by the key that was typed. This is the final character that results after all modifiers have been applied. For example, when the user types Ctrl+A, the character value is 0x01 (ASCII SOH). It is important that applications do not attempt to modify the character value based on a stateMask (such as SWT.CTRL) or the resulting character will not be correct.

countback to summary
public int count

depending on the event type, the number of following paint events that are pending which may always be zero on some platforms, or the number of lines or pages to scroll using the mouse wheel, or the number of times the mouse has been clicked

databack to summary
public Object data

a field for application use

detailback to summary
public int detail

the event specific detail field, as defined by the detail constants in class SWT

See Also
org.eclipse.swt.SWT
displayback to summary
public Display display

the display where the event occurred

Since
2.0
doitback to summary
public boolean doit

depending on the event, a flag indicating whether the operation should be allowed. Setting this field to false will cancel the operation.

endback to summary
public int end

depending on the event, the range of text being modified. Setting these fields only has effect during ImeComposition events.

gcback to summary
public GC gc

the graphics context to use when painting that is configured to use the colors, font and damaged region of the control. It is valid only during the paint and must not be disposed

heightback to summary
public int height

the height of the bounding rectangle of the region that requires painting

indexback to summary
public int index

the index of the item where the event occurred

Since
3.2
itemback to summary
public Widget item

the item that the event occurred in (can be null)

keyCodeback to summary
public int keyCode

character that is good for keyboard shortcut comparison. Unlike character, this tries to ignore modifier keys and deal with non-latin keyboard layouts. Examples:

LayoutUS key labelcharacterkeyCode
Windows English US C 'c' 'c'
Windows English US Shift+C'C' 'c'
Windows English US Ctrl+C 0x03'c'
Windows English DvorakI 'c' 'c'
Windows Bulgarian Ъ 'ъ' 'c'
Windows French 2 'é' '2'
Windows French Shift+2'2' '2'

How it is done differs per platform, and on many platforms, SWT resorts to various magic. To understand the problem, consider the following questions about the well known Ctrl+C shortcut:
  • Which key invokes Ctrl+C in English? Well, that's easy, key C does it.
  • Dvorak is basically an English layout, but with keys shuffled around. Where English has C, Dvorak has J. Where English has I, Dvorak has C. Which key invokes Ctrl+C in English-Dvorak? Well, both answers are kind of correct. There's a heated debate on the internet which answer is better: some argue that they like English shortcuts they learned before they decided to try Dvorak. Others argue that key labels shall match invoked shortcuts. The usually preferred answer is that if a key types C in Dvorak, then it shall invoke Ctrl+C. That is, the key that is labeled I in English.
  • Which key invokes Ctrl+C in non-latin keyboard layouts? That's where it gets hard. Consider Hebrew, Cyrillic, Japanese. These layouts simply don't have latin C anywhere!
Approaching all 3 questions at once is non-trivial, and each OS does it in a different way. In very simple words:
  • Windows keyboard layouts have an additional invisible mapping of keys to keyboard shortcuts, completely independent from characters typed by these keys. Layouts also have the regular mapping of keys to produced characters. Both are edited in keyboard layout editors.
  • macOS keyboard layouts have hidden Latin sub-layouts and switch to them when a modifier such as Cmd is pressed. This is easy to see in builtin on-screen keyboard. It's a lot more complicated with modifiers other than Cmd and Ctrl.
  • Linux is worst. It lacks the information to map shortcuts on non-latin keyboards and resorts to inspecting other installed layouts to find something latin.
For detailed information, see Widget#setKeyState per platform.
See Also
org.eclipse.swt.SWT
keyLocationback to summary
public int keyLocation

depending on the event, the location of key specified by the keyCode or character. The possible values for this field are SWT.LEFT, SWT.RIGHT, SWT.KEYPAD, or SWT.NONE representing the main keyboard area.

The location field can be used to differentiate key events that have the same key code and character but are generated by different keys in the keyboard. For example, a key down event with the key code equals to SWT.SHIFT can be generated by the left and the right shift keys in the keyboard. The location field can only be used to determine the location of the key code or character in the current event. It does not include information about the location of modifiers in state mask.

Since
3.6
See Also
org.eclipse.swt.SWT#LEFT, org.eclipse.swt.SWT#RIGHT, org.eclipse.swt.SWT#KEYPAD
magnificationback to summary
public double magnification

The change in magnification. This value should be added to the current scaling of an item to get the new scale factor.

Since
3.7
rotationback to summary
public double rotation

The number of degrees rotated on the track pad.

Since
3.7
segmentsback to summary
public int[] segments

Bidi segment offsets

Since
3.8
segmentsCharsback to summary
public char[] segmentsChars

Characters to be applied on the segment boundaries

Since
3.8
startback to summary
public int start

depending on the event, the range of text being modified. Setting these fields only has effect during ImeComposition events.

stateMaskback to summary
public int stateMask

depending on the event, the state of the keyboard modifier keys and mouse masks at the time the event was generated.

See Also
org.eclipse.swt.SWT#MODIFIER_MASK, org.eclipse.swt.SWT#BUTTON_MASK
textback to summary
public String text

depending on the event, the new text that will be inserted. Setting this field will change the text that is about to be inserted or deleted.

timeback to summary
public int time

the time that the event occurred.

Note

This field is an unsigned integer and should be AND'ed with 0xFFFFFFFFL so that it can be treated as a signed long.

touchesback to summary
public Touch[] touches

An array of the touch states for the current touch event.

Since
3.7
typeback to summary
public int type

the type of event, as defined by the event type constants in class SWT

See Also
org.eclipse.swt.SWT
widgetback to summary
public Widget widget

the widget that issued the event

widthback to summary
public int width

the width of the bounding rectangle of the region that requires painting

xback to summary
public int x

depending on the event type, the x offset of the bounding rectangle of the region that requires painting or the widget-relative, x coordinate of the pointer at the time the mouse button was pressed or released

xDirectionback to summary
public int xDirection

If nonzero, a positive value indicates a swipe to the right, and a negative value indicates a swipe to the left.

Since
3.7
yback to summary
public int y

depending on the event type, the y offset of the bounding rectangle of the region that requires painting or the widget-relative, y coordinate of the pointer at the time the mouse button was pressed or released

yDirectionback to summary
public int yDirection

If nonzero, a positive value indicates a swipe in the up direction, and a negative value indicates a swipe in the down direction.

Since
3.7

Constructor Detail

Eventback to summary
public Event()

Method Detail

getBoundsback to summary
public Rectangle getBounds()

Gets the bounds.

Returns:Rectangle

a rectangle that is the bounds.

getBoundsInPixelsback to summary
pack-priv Rectangle getBoundsInPixels()
getLocationback to summary
pack-priv Point getLocation()
getLocationInPixelsback to summary
pack-priv Point getLocationInPixels()
setBoundsback to summary
public void setBounds(Rectangle rect)

Sets the bounds.

Parameters
rect:Rectangle

the new rectangle

setBoundsInPixelsback to summary
pack-priv void setBoundsInPixels(Rectangle rect)
setLocationInPixelsback to summary
pack-priv void setLocationInPixels(int x, int y)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.

Returns:String

a string representation of the event

Annotations
@Override