Chapter 6. More SWT

As previously explained, the Standard Widget Toolkit (SWT) consists of a set of tools developed by the Eclipse project in order to help building Graphical User Interface (GUI) applications.

In Chapter 5, SWT, we have introduced some basic concepts regarding the SWT API. This knowledge is important so that we can easily follow the content presented in this chapter. For the later sections of this chapter, we delve deep into SWT events, and show how to deal with menus, toolbars, dialogs, and tables.

Events

In several examples of our previous chapter, despite not being the focus of what we were trying to explain, we have shown how to deal with a few user events, such as the click of button, for instance. For every action a user takes, such as a mouse click, or a pressed key, an event is generated by the operating system. We can choose to handle what is considered relevant for the application being developed. To capture an event, it is necessary to add listeners to the code, that must be attached to an interface element, such as a shell, a composite, or a widget, present in a container.

The main process starts with the operating system event queue, that deals (record and list) with actions taken by an user. When an SWT application is being executed, the Display class uses the readAndDispatch method to monitor the messages from the operating system. It sorts through the relevant ones and sends them to the shell object, which is responsible for redirecting it to the associated widget. The information regarding the event is finally caught by the widget listener, which then invokes a method to handle the event.

In this chapter, we will discuss how to deal with events related to the SWT API, and illustrate our explanation with some examples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset