SWT/JFace in Action
eBook - ePub

SWT/JFace in Action

GUI Design with Eclipse 3.0

Matthew Scarpino, Laurent Mihalkovic, Stanford Ng, Stephen Holder

Share book
  1. 496 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

SWT/JFace in Action

GUI Design with Eclipse 3.0

Matthew Scarpino, Laurent Mihalkovic, Stanford Ng, Stephen Holder

Book details
Book preview
Table of contents
Citations

About This Book

Covering Eclipse's new capability for building graphical user interfaces with version 3.0, the Standard Widget Toolkit (SWT) and JFace, this guide demonstrates how these award-winning tools have received broad support for creating desktop applications. Theory and practical examples reveal how to build GUIs that combine the look and feel of native interfaces with the platform independence of Java. This guide also shows how SWT makes use of the widgets provided by the operating system and describes how these components can be associated with events, containers, and graphics. With this knowledge, programmers can build fully featured user interfaces that communicate directly with the underlying platform. JFace's ability to simplify and organize the process of GUI design is then demonstrated, enabling developers to modify and adapt components, and separate their information from their appearance.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is SWT/JFace in Action an online PDF/ePUB?
Yes, you can access SWT/JFace in Action by Matthew Scarpino, Laurent Mihalkovic, Stanford Ng, Stephen Holder in PDF and/or ePUB format, as well as other popular books in Informatik & Programmierung in Java. We have over one million books available in our catalogue for you to explore.

Information

Publisher
Manning
Year
2004
ISBN
9781638354949

Chapter 1. Overview of SWT and JFace

This chapter covers
  • The purpose of SWT and JFace
  • The reasons for their creation
  • How the two libraries differ from Swing
  • Licensing and platform support
In March 2004, the Java Developer’s Journal announced the results of its Readers’ Choice Award for Best Java Component. More than 15,000 developers voted for one of many Java toolsets, including offerings from such established names as Oracle and Apple. But in the end, Eclipse’s Standard Widget Toolkit (SWT) won handily, just as it did in 2003. Despite their late entry into the field of Java development, Eclipse and SWT have also won awards and recognition from JavaWorld, JavaPro, and LinuxWorld.
This well-earned applause goes a long way in showing the impact these tools have made on Java development. Java programmers around the world have embraced the power and versatility of SWT and JFace, deploying new plug-ins and standalone applications with each passing day. The goal of this book is to show you how this toolset functions and how you can use these tools for your own applications.
In particular, you’ll be able to
  • Develop SWT/JFace-based applications with hands-on code examples
  • Create customized graphics with SWT’s built-in graphical context
  • Understand the structure and methodology behind the SWT/JFace API
  • Further your knowledge of GUI (graphical user interface) design
  • Build and deploy SWT/JFace applications for Eclipse and standalone usage
Most important, GUI development should be fun! No other branch of programming provides the same satisfaction as watching a new graphical interface spring to life. Therefore, we’ll intersperse the theory of SWT and JFace with example code showing practical GUI development.
But before we start programming, we need to show you what this new technology is all about and what tasks it will help you perform.

1.1. What is SWT/JFace?

Although we refer to SWT and JFace as tools or toolsets, they’re essentially software libraries. They consist of packages that contain Java classes and interfaces. But what makes these components so special is that you can combine them to form GUIs. And not just any GUIs, either! Your applications will run quickly, make effective use of computer memory, and, like chameleons, assume the look and feel of whichever Java-supported operating system they run on. No other GUI-building library can say that.
Although SWT and JFace accomplish the same goal, they follow different philosophies in creating user interfaces. Our favorite analogy involves automobile transmissions. SWT development is like using a standard transmission: It gives you greater control and access to the system internals, but it’s more complicated to use. JFace, on the other hand, resembles an automatic transmission: It does most of the work for you, but you lose flexibility.
Of course, the truth is more complicated than any analogy. So, let’s investigate these two libraries in greater depth.

1.1.1. Building GUIs with SWT

Every operating system contains a number of graphical components that make up its default user interface. These include buttons, windows, menus, and everything else you see on your computer screen. The goal of SWT is to give you, the Java programmer, direct access to these components so that you can configure and position them however you like.
You don’t have to worry about the end user’s operating system. When you add an SWT Button object to your application, it will look and act like a Windows button on Windows, a Macintosh button on Macintosh, and a Linux button on a Linux system. Users will think that you wrote the GUI specifically for their machines, and they’ll have no idea that you wrote the code only once using SWT.
In addition to graphical components, SWT also provides access to events. This means you can keep track of what buttons your users have clicked and which menu items they’ve selected. This powerful capability makes it possible to receive and respond to nearly every form of user input, and we’ll spend a great deal of time showing how this works.
Finally, if you want to add graphics to your application, SWT provides a large set of tools for creating images, working with new fonts, and drawing shapes. This feature not only allows you to build new graphics, but also lets you control how, when, and where they’re displayed in your GUI. This book will show you how SWT manages colors, drawings, fonts, and images, and will present a great deal of example code.
SWT provides a wealth of capabilities for building user interfaces, but as you’ll see in this book, the code can become lengthy and complex. For this reason, the Eclipse designers built a second library for GUI development: JFace.

1.1.2. Simplifying GUI development with JFace

Rather than write the same SWT code over and over again, the designers of the Eclipse Workbench created JFace. This library provides shortcuts around many of the tasks that can be time-consuming using SWT alone. But JFace is not a replacement for SWT, and many GUIs will need features from both toolsets.
An important example of JFace’s increased efficiency involves events. In many user interfaces, you may have different events, such as button clicks, keystrokes, or menu selections, that all perform the same function. In SWT, each event needs to be received and handled separately. But JFace allows you to combine them into a single object, so you can concern yourself with the event’s response instead of the component that triggered it. This simple but powerful concept makes it possible to add context menus, toolbars, and palettes to your GUIs without adding a lot of code.
JFace is also helpful when you’re building large GUIs that require multiple windows and graphics. It provides registry classes that help you organize SWT components and manage their memory allocation. For example, in SWT, you need to specifically create and deallocate every Font and Image in your application. But with JFace, you can use built-in FontRegistry and ImageRegistry objects to take care of these tedious concerns for you.
Now that you understand the basic characteristics behind these two libraries, we need to dig a little deeper and show you the concepts behind their design. This discussion will explain why SWT/JFace GUIs are so fast, why they can take the appearance of whatever operating system they run on, and why they were created in the first place.

1.2. Looking under the hood

Adding components, events, and graphics to a user interface isn’t a new idea. Therefore, to see why the SWT/JFace toolset has caused such a stir, you need to understand what its designers were thinking. This means investigating the principles behind Java GUI development and how these libraries make use of them.
But before we can investigate SWT/JFace in depth, we need to introduce Swing. SWT and JFace were created in response to this library, and by understanding the contrast between the two design philosophies, you’ll better appreciate how SWT and JFace function. Further, in addition to recognizing the trade-offs between Swing and SWT/JFace, you’ll be able to participate in the passionate debates concerning the two.

1.2.1. The old standby: Swing

When Sun released the Swing library in 1998, the Java community was delighted. Finally, Sun had backed up its “Write Once, Run Anywhere” credo with a toolset capable of building platform-independent user interfaces. Swing quickly became the most popular tool for creating GUIs in Java.
But as time went by, many developers became discontented. The qualities that made Swing so attractive initially also made for complex development and slow operation. For this reason, Java GUIs have found little use in desktop applications.
Swing rendering
In order to ensure consistent appearance and operation across operating systems, Swing takes complete control of rendering its user interfaces...

Table of contents