Standard Widget Toolkit
Encyclopedia
The Standard Widget Toolkit (SWT) is a graphical widget toolkit
for use with the Java platform. It was originally developed by IBM
and is now maintained by the Eclipse Foundation
in tandem with the Eclipse IDE. It is an alternative to the AWT
and Swing
Java GUI
toolkits provided by Sun Microsystems
as part of the Java Platform, Standard Edition
.
To display GUI elements, the SWT implementation accesses the native GUI libraries of the operating system using JNI (Java Native Interface
) in a manner that is similar to those programs written using operating system-specific API
s. Programs that call SWT are portable, but the implementation of the toolkit, despite part of it being written in Java
, is unique for each platform.
The toolkit is licensed under the Eclipse Public License
, an Open Source Initiative
approved open source
license.
) was the first Java GUI toolkit, introduced with JDK
1.0 as one component of the Sun Microsystems Java platform. The original AWT was a simple Java wrapper around native (operating system
-supplied) widgets
such as menus, windows and buttons.
Swing
was the next generation GUI toolkit introduced by Sun in J2SE 1.2
. Swing was developed in order to provide a richer set of GUI components than AWT. Swing GUI elements are 100% Java with no native code: instead of wrapping native GUI components, Swing draws its own components by using Java2D to call low level operating system drawing routines.
The roots of SWT go back to work that Object Technology International
, or OTI, did in the 1990s when creating multiplatform, portable, native widget interfaces for Smalltalk
(originally for OTI Smalltalk, which became IBM Smalltalk in 1993). IBM Smalltalk's Common Widget layer provided fast, native access to multiple platform widget sets while still providing a common API without suffering the "lowest common denominator" problem typical of other portable graphical user interface (GUI) toolkits. IBM
was developing VisualAge
, an integrated development environment
(IDE) written in Smalltalk
. They decided to open-source the project, which led to the development of Eclipse
, intended to compete against other IDEs such as Microsoft Visual Studio
. Eclipse is written in Java, and IBM developers, deciding that they needed a toolkit that had "native look and feel
" and "native performance
", created SWT as a Swing replacement.
objects, Motif
objects etc. Because of this, SWT widgets are often referred to as "heavyweight", evoking images of a light Java wrapper around a "heavy" native object. In cases where native platform GUI libraries do not support the functionality required for SWT, SWT implements its own GUI code in Java, similar to Swing. In essence, SWT is a compromise between the low level performance and look and feel of AWT and the high level ease of use of Swing.
According to the Eclipse Foundation, "SWT and Swing are different tools that were built with different goals in mind. The purpose of SWT is to provide a common API for accessing native widgets across a spectrum of platforms. The primary design goals are high performance, native look and feel, and deep platform integration. Swing, on the other hand, is designed to allow for a highly customizable look and feel that is common across all platforms."
It has been argued that SWT features a clean design, in part inspired by Erich Gamma
of Design Patterns
fame.
SWT is a simpler toolkit than Swing, with less (possibly) extraneous functionality for the average developer. This has led some people to argue that SWT lacks functionality when compared to Swing.
James Gosling
, the creator of the Java language, has argued that SWT is too simple, and that SWT is a difficult toolkit to port to new platforms for the same reason that AWT used to have porting problems: that it is too simple, too low level, and too tied to the Win32 GUI API, leading to problems adapting the SWT API to other GUI toolkits, such as Motif and OS X Carbon.
Although SWT does not implement the popular Model-View-Controller
architecture used in Swing and many other high level GUI toolkits, the JFace
library, which is developed as part of the same Eclipse project, does provide a platform-independent, higher-level Model-View-Controller abstraction on top of SWT. Developers may choose to use JFace to provide more flexible and abstract data models for complex SWT controls such as trees, tables and lists, or access those controls directly as needed.
" as native widgets because they often are the same native widgets. This is in contrast to the Swing toolkit where all widgets are emulations of native widgets. In some cases the difference is distinguishable. For example the Mac OS X
tree widget features a subtle animation when a tree is expanded and default buttons actually have an animated pulsing glow to focus the user's attention on them. The default Swing version of these widgets do not animate.
Since SWT is simply a wrapper around native GUI code, it does not require large numbers of updates when that native code is changed, providing that operating system vendors are careful not to break clients of their API when the operating systems are updated. The same cannot be said of Swing: Swing supports the ability to change the look and feel of the running application with "pluggable look and feels" which enable emulating the native platform user interface using theme
s, which must be updated to mirror operating system GUI changes (such as theme or other look and feel updates).
SWT aims for "deep platform integration", the Eclipse reference to SWT's use of native widgets. According to Mauro Marinillia of developer.com, "whenever one needs a tight integration with the native platform, SWT can be a plus". This deep integration can be useful in a number of ways, for example enabling SWT to wrap ActiveX
objects on Microsoft Windows
.
Contrary to Swing
, a Display class is necessary to access the underlying operating system
, and its resources must be explicitly disposed of when they are no longer used.
SWT exposes developers to more low level details than Swing. This is because SWT is technically just a layer over native library provided GUI functionality, exposing the programmer to native GUI code is part of the design intent of SWT: "Its goal is not to provide a rich user-interface design framework but rather the thinnest possible user-interface API that can be implemented uniformly on the largest possible set of platforms while still providing sufficient functionality to build rich graphical user interface (GUI) applications."
Since the SWT implementation is different for each platform, a platform-specific SWT library (JAR file) must be distributed with each application.
As of July 2008 SWT supports the following platforms and/or GUI libraries:
of SWT and Swing, which concluded that SWT was more efficient than Swing, although the applications benchmarked in this case were not complex enough to draw solid conclusions for all possible SWT or Swing uses. A fairly thorough set of benchmarks concluded that neither Swing nor SWT clearly outperformed the other in the general case.
SWT widgets, unlike almost any other Java toolkit, requires manual object deallocation, as opposed to the standard Java practice of automatic garbage collection. SWT objects must be explicitly deallocated using the ".dispose" function, which is analogous to the C language
's "free". If this is not done, memory leak
s or other unintended behavior may result. On this matter, some have commented that "explicitly de-allocating the resources could be a step back in development time (and costs) at least for the average Java developer." and that "this is a mixed blessing. It means more control (and more complexity) for the SWT developer instead of more automation (and slowness) when using Swing." The need for manual object deallocation when using SWT is largely due to SWT's use of native objects. As these objects are not tracked by the Java JVM, the JVM is unable to ascertain whether or not these native objects are in use, and thus unable to garbage collect them at an appropriate time.
In practice, the only SWT objects which a developer must explicitly dispose are the subclasses of Resource, such as Image, Color, and Font objects.
Starting in 2006 there was a SWT-3.2 port to the D programming language called DWT. Since then the project supports Windows 32-bit and also Linux GTK 32-bit for SWT-3.4. The DWT project also has an addon package that contains a port of JFace
and Eclipse Forms.
Recent open source efforts in the eclipse community have led to a porting of SWT (and JFace) into a widget toolkit appropriate for the web. The result has been the Eclipse RAP
, which combines the qooxdoo
AJAX library with the SWT API. Like other Java AJAX
projects (such as Echo2
, Vaadin
and Google Web Toolkit
), the usage of the SWT API allows developers to quickly develop applications for the web in much the same way as they would for the desktop.
Widget toolkit
In computing, a widget toolkit, widget library, or GUI toolkit is a set of widgets for use in designing applications with graphical user interfaces...
for use with the Java platform. It was originally developed by IBM
IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
and is now maintained by the Eclipse Foundation
Eclipse Foundation
The Eclipse Foundation is a not-for-profit, member supported corporation that hosts the open-source Eclipse Projects and helps cultivate both an open source community and an ecosystem of complementary products and services...
in tandem with the Eclipse IDE. It is an alternative to the AWT
Abstract Window Toolkit
The Abstract Window Toolkit is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes — the standard API for providing a graphical user interface for a Java program.AWT is also the GUI toolkit for a...
and Swing
Swing (Java)
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....
Java GUI
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...
toolkits provided by Sun Microsystems
Sun Microsystems
Sun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...
as part of the Java Platform, Standard Edition
Java Platform, Standard Edition
Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use...
.
To display GUI elements, the SWT implementation accesses the native GUI libraries of the operating system using JNI (Java Native Interface
Java Native Interface
The Java Native Interface is a programming framework that enables Java code running in a Java Virtual Machine to call and to be called by native applications and libraries written in other languages such as C, C++ and assembly.-Purpose and features:JNI enables one to write native methods to...
) in a manner that is similar to those programs written using operating system-specific API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
s. Programs that call SWT are portable, but the implementation of the toolkit, despite part of it being written in Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
, is unique for each platform.
The toolkit is licensed under the Eclipse Public License
Eclipse Public License
The Eclipse Public License is an open source software license used by the Eclipse Foundation for its software. It replaces the Common Public License and removes certain terms relating to litigations related to patents....
, an Open Source Initiative
Open Source Initiative
The Open Source Initiative is an organization dedicated to promoting open source software.The organization was founded in February 1998, by Bruce Perens and Eric S. Raymond, prompted by Netscape Communications Corporation publishing the source code for its flagship Netscape Communicator product...
approved open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
license.
History
AWT (the Abstract Window ToolkitAbstract Window Toolkit
The Abstract Window Toolkit is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes — the standard API for providing a graphical user interface for a Java program.AWT is also the GUI toolkit for a...
) was the first Java GUI toolkit, introduced with JDK
Java Development Kit
The Java Development Kit is an Oracle Corporation product aimed at Java developers. Since the introduction of Java, it has been by far the most widely used Java SDK. On 17 November 2006, Sun announced that it would be released under the GNU General Public License , thus making it free software...
1.0 as one component of the Sun Microsystems Java platform. The original AWT was a simple Java wrapper around native (operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
-supplied) widgets
Widget (computing)
In computer programming, a widget is an element of a graphical user interface that displays an information arrangement changeable by the user, such as a window or a text box. The defining characteristic of a widget is to provide a single interaction point for the direct manipulation of a given...
such as menus, windows and buttons.
Swing
Swing (Java)
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....
was the next generation GUI toolkit introduced by Sun in J2SE 1.2
Java Platform, Standard Edition
Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use...
. Swing was developed in order to provide a richer set of GUI components than AWT. Swing GUI elements are 100% Java with no native code: instead of wrapping native GUI components, Swing draws its own components by using Java2D to call low level operating system drawing routines.
The roots of SWT go back to work that Object Technology International
Object Technology International
Object Technology International was founded in Ottawa, Ontario in 1988 and acquired by IBM in 1996. OTI was the company behind the VisualAge line Smalltalk and Java development tools that eventually culminated in the open source Eclipse tool platform and integrated development environment .OTI...
, or OTI, did in the 1990s when creating multiplatform, portable, native widget interfaces for Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...
(originally for OTI Smalltalk, which became IBM Smalltalk in 1993). IBM Smalltalk's Common Widget layer provided fast, native access to multiple platform widget sets while still providing a common API without suffering the "lowest common denominator" problem typical of other portable graphical user interface (GUI) toolkits. IBM
IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
was developing VisualAge
VisualAge
VisualAge was the name of a family of computer integrated development environments from IBM, which included support for multiple programming languages. VisualAge was first released in the 1980s and is still available in 2011...
, an integrated development environment
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...
(IDE) written in Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...
. They decided to open-source the project, which led to the development of Eclipse
Eclipse (software)
Eclipse is a multi-language software development environment comprising an integrated development environment and an extensible plug-in system...
, intended to compete against other IDEs such as Microsoft Visual Studio
Microsoft Visual Studio
Microsoft Visual Studio is an integrated development environment from Microsoft. It is used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all...
. Eclipse is written in Java, and IBM developers, deciding that they needed a toolkit that had "native look and feel
Look and feel
In software design, look and feel is a term used in respect of a graphical user interface and comprises aspects of its design, including elements such as colors, shapes, layout, and typefaces , as well as the behavior of dynamic elements such as buttons, boxes, and menus...
" and "native performance
Performance
A performance, in performing arts, generally comprises an event in which a performer or group of performers behave in a particular way for another group of people, the audience. Choral music and ballet are examples. Usually the performers participate in rehearsals beforehand. Afterwards audience...
", created SWT as a Swing replacement.
Design
SWT is a wrapper around native code objects, such as GTK+GTK+
GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...
objects, Motif
Motif (widget toolkit)
In computing, Motif refers to both a graphical user interface specification and the widget toolkit for building applications that follow that specification under the X Window System on Unix and other POSIX-compliant systems. It emerged in the 1980s as Unix workstations were on the rise, as a...
objects etc. Because of this, SWT widgets are often referred to as "heavyweight", evoking images of a light Java wrapper around a "heavy" native object. In cases where native platform GUI libraries do not support the functionality required for SWT, SWT implements its own GUI code in Java, similar to Swing. In essence, SWT is a compromise between the low level performance and look and feel of AWT and the high level ease of use of Swing.
According to the Eclipse Foundation, "SWT and Swing are different tools that were built with different goals in mind. The purpose of SWT is to provide a common API for accessing native widgets across a spectrum of platforms. The primary design goals are high performance, native look and feel, and deep platform integration. Swing, on the other hand, is designed to allow for a highly customizable look and feel that is common across all platforms."
It has been argued that SWT features a clean design, in part inspired by Erich Gamma
Erich Gamma
Erich Gamma is Swiss computer scientist and co-author of the influential Software engineering textbook, Design Patterns: Elements of Reusable Object-Oriented Software. He co-wrote the JUnit software testing framework with Kent Beck and led the design of the Eclipse platform's Java Development Tools...
of Design Patterns
Design Patterns
Design Patterns: Elements of Reusable Object-Oriented Software is a software engineering book describing recurring solutions to common problems in software design. The book's authors are Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides with a foreword by Grady Booch. The authors are...
fame.
SWT is a simpler toolkit than Swing, with less (possibly) extraneous functionality for the average developer. This has led some people to argue that SWT lacks functionality when compared to Swing.
James Gosling
James Gosling
James A. Gosling, OC is a computer scientist, best known as the father of the Java programming language.-Education and career:In 1977, Gosling received a B.Sc in Computer Science from the University of Calgary...
, the creator of the Java language, has argued that SWT is too simple, and that SWT is a difficult toolkit to port to new platforms for the same reason that AWT used to have porting problems: that it is too simple, too low level, and too tied to the Win32 GUI API, leading to problems adapting the SWT API to other GUI toolkits, such as Motif and OS X Carbon.
Although SWT does not implement the popular Model-View-Controller
Model-view-controller
Model–view–controller is a software architecture, currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" from the user interface , permitting independent development, testing and maintenance of each .Model View Controller...
architecture used in Swing and many other high level GUI toolkits, the JFace
JFace
JFace is defined by the Eclipse project as "a UI toolkit that provides helper classes for developing UI features that can be tedious to implement." It is a layer that sits on top of the raw widget system, and provides classes for handling common UI programming tasks...
library, which is developed as part of the same Eclipse project, does provide a platform-independent, higher-level Model-View-Controller abstraction on top of SWT. Developers may choose to use JFace to provide more flexible and abstract data models for complex SWT controls such as trees, tables and lists, or access those controls directly as needed.
Look and feel
SWT widgets have the same "look and feelLook and feel
In software design, look and feel is a term used in respect of a graphical user interface and comprises aspects of its design, including elements such as colors, shapes, layout, and typefaces , as well as the behavior of dynamic elements such as buttons, boxes, and menus...
" as native widgets because they often are the same native widgets. This is in contrast to the Swing toolkit where all widgets are emulations of native widgets. In some cases the difference is distinguishable. For example the Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
tree widget features a subtle animation when a tree is expanded and default buttons actually have an animated pulsing glow to focus the user's attention on them. The default Swing version of these widgets do not animate.
Since SWT is simply a wrapper around native GUI code, it does not require large numbers of updates when that native code is changed, providing that operating system vendors are careful not to break clients of their API when the operating systems are updated. The same cannot be said of Swing: Swing supports the ability to change the look and feel of the running application with "pluggable look and feels" which enable emulating the native platform user interface using theme
Theme (computing)
In computing, a theme is a preset package containing graphical appearance details, used to customize the look and feel of an operating system, widget set or window manager....
s, which must be updated to mirror operating system GUI changes (such as theme or other look and feel updates).
SWT aims for "deep platform integration", the Eclipse reference to SWT's use of native widgets. According to Mauro Marinillia of developer.com, "whenever one needs a tight integration with the native platform, SWT can be a plus". This deep integration can be useful in a number of ways, for example enabling SWT to wrap ActiveX
ActiveX
ActiveX is a framework for defining reusable software components in a programming language-independent way. Software applications can then be composed from one or more of these components in order to provide their functionality....
objects on Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
.
Programming
The following is a basic Hello World program using SWT. It shows a window (Shell) and a label.Contrary to Swing
Swing (Java)
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....
, a Display class is necessary to access the underlying operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
, and its resources must be explicitly disposed of when they are no longer used.
Platform support
SWT must be ported to every new GUI library that needs supporting. Unlike Swing and AWT, SWT is not available on every Java-supported platform since SWT is not part of the Java release. There is also some evidence that the performance of SWT on platforms other than Windows is noticeably less efficient. Since SWT uses a different native library for each platform, SWT developers may be exposed to platform-specific bugs.SWT exposes developers to more low level details than Swing. This is because SWT is technically just a layer over native library provided GUI functionality, exposing the programmer to native GUI code is part of the design intent of SWT: "Its goal is not to provide a rich user-interface design framework but rather the thinnest possible user-interface API that can be implemented uniformly on the largest possible set of platforms while still providing sufficient functionality to build rich graphical user interface (GUI) applications."
Since the SWT implementation is different for each platform, a platform-specific SWT library (JAR file) must be distributed with each application.
As of July 2008 SWT supports the following platforms and/or GUI libraries:
- Windows XPWindows XPWindows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...
, Windows VistaWindows VistaWindows Vista is an operating system released in several variations developed by Microsoft for use on personal computers, including home and business desktops, laptops, tablet PCs, and media center PCs...
:- Win32
- WPFWindows Presentation FoundationDeveloped by Microsoft, the Windows Presentation Foundation is a computer-software graphical subsystem for rendering user interfaces in Windows-based applications. WPF, previously known as "Avalon", was initially released as part of .NET Framework 3.0. Rather than relying on the older GDI...
(under development)
- AIX, FreeBSDFreeBSDFreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...
, LinuxLinuxLinux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
, HP-UXHP-UXHP-UX is Hewlett-Packard's proprietary implementation of the Unix operating system, based on UNIX System V and first released in 1984...
, Solaris:- MotifMotif (widget toolkit)In computing, Motif refers to both a graphical user interface specification and the widget toolkit for building applications that follow that specification under the X Window System on Unix and other POSIX-compliant systems. It emerged in the 1980s as Unix workstations were on the rise, as a...
- GTK+GTK+GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...
- Motif
- Mac OS XMac OS XMac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
:- CarbonCarbon (API)Carbon is one of Apple Inc.'s procedural application programming interfaces for the Macintosh operating system. It provides C programming language access to Macintosh system services...
- CocoaCocoa (API)Cocoa is Apple's native object-oriented application programming interface for the Mac OS X operating system and—along with the Cocoa Touch extension for gesture recognition and animation—for applications for the iOS operating system, used on Apple devices such as the iPhone, the iPod Touch, and...
- Carbon
- QNX Photon
- Pocket PCPocket PCA Pocket PC is also known by Microsoft as a 'Windows Mobile Classic device'. It is a hardware specification for a handheld-sized computer, personal digital assistant , that runs the Microsoft 'Windows Mobile Classic' operating system...
Performance
SWT was designed to be a "high performance" GUI toolkit; faster, more responsive and lighter on system resource usage than Swing. There has been some attempted benchmarkingBenchmark (computing)
In computing, a benchmark is the act of running a computer program, a set of programs, or other operations, in order to assess the relative performance of an object, normally by running a number of standard tests and trials against it...
of SWT and Swing, which concluded that SWT was more efficient than Swing, although the applications benchmarked in this case were not complex enough to draw solid conclusions for all possible SWT or Swing uses. A fairly thorough set of benchmarks concluded that neither Swing nor SWT clearly outperformed the other in the general case.
Extensibility and comparison to other Java code
Due to the use of native code, SWT classes do not allow for easy inheritance for all widget classes, which some people consider can hurt extensibility. This can make customizing existing widgets more difficult to achieve with SWT than if one were using Swing. Both toolkits support writing new widgets using only Java code, however in SWT extra work is needed to make the new widget work on every platform.SWT widgets, unlike almost any other Java toolkit, requires manual object deallocation, as opposed to the standard Java practice of automatic garbage collection. SWT objects must be explicitly deallocated using the ".dispose" function, which is analogous to the C language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
's "free". If this is not done, memory leak
Memory leak
A memory leak, in computer science , occurs when a computer program consumes memory but is unable to release it back to the operating system. In object-oriented programming, a memory leak happens when an object is stored in memory but cannot be accessed by the running code...
s or other unintended behavior may result. On this matter, some have commented that "explicitly de-allocating the resources could be a step back in development time (and costs) at least for the average Java developer." and that "this is a mixed blessing. It means more control (and more complexity) for the SWT developer instead of more automation (and slowness) when using Swing." The need for manual object deallocation when using SWT is largely due to SWT's use of native objects. As these objects are not tracked by the Java JVM, the JVM is unable to ascertain whether or not these native objects are in use, and thus unable to garbage collect them at an appropriate time.
In practice, the only SWT objects which a developer must explicitly dispose are the subclasses of Resource, such as Image, Color, and Font objects.
Development
There is some activity to enable combining Swing and SWT. There are two different approaches being attempted:- SwingWT is a project which intends to provide Swing developers with an alternative Swing implementation: one which uses an SWT back end to display its widgets, thus providing the native look and feel and performance advantages of SWT along with the same programming model as Swing.
- SWTSwing is a project which intends to provide a Swing back end for SWT. In effect, SWT could be run using "Swing native objects" instead of, for example, GTK or Windows native objects. This would enable SWT to work on every platform that Swing supports.
Starting in 2006 there was a SWT-3.2 port to the D programming language called DWT. Since then the project supports Windows 32-bit and also Linux GTK 32-bit for SWT-3.4. The DWT project also has an addon package that contains a port of JFace
JFace
JFace is defined by the Eclipse project as "a UI toolkit that provides helper classes for developing UI features that can be tedious to implement." It is a layer that sits on top of the raw widget system, and provides classes for handling common UI programming tasks...
and Eclipse Forms.
Uses
Applications using SWT include:- IBM Rational SoftwareRational SoftwareRational Machines was founded by Paul Levy and Mike Devlin in 1981 to provide tools to expand the use of modern software engineering practices, particularly explicit modular architecture and iterative development...
products: Rational Application DeveloperRational Application DeveloperIBM Rational Application Developer for WebSphere Software is a commercial Eclipse-based integrated development environment , made by IBM's Rational Software division, for visually designing, constructing, testing, and deploying Web services, portals, and Java Enterprise Edition ...
, Rational Software Architect, Rational Team Concert and others. - IBM Lotus SoftwareLotus SoftwareLotus Software is a software company with headquarters in Westford, Massachusetts...
including NotesLotus NotesLotus Notes is the client of a collaborative platform originally created by Lotus Development Corp. in 1989. In 1995 Lotus was acquired by IBM and became known as the Lotus Development division of IBM and is now part of the IBM Software Group...
, SametimeLotus SametimeIBM Sametime is a client–server application and middleware platform that provides real-time, unified communications and collaboration for enterprises. Those capabilities include presence information, enterprise instant messaging, web conferencing, community collaboration, and telephony capabilities...
, SymphonyIBM Lotus SymphonyIBM Lotus Symphony is a suite of applications for creating, editing, and sharing text, spreadsheet, presentations and other documents, and is currently distributed as freeware. First released in 2007, the suite has a name similar to the 1980s DOS suite Lotus Symphony, but the two programs are...
and Expeditor - VuzeVuzeVuze is a BitTorrent client used to transfer files via the BitTorrent protocol. Vuze is written in Java, and uses the Azureus Engine. In addition to downloading data linked to by .torrent files, Azureus allows users to view, publish and share original DVD and HD quality video content...
, formerly known as Azureus - EclipseEclipse (software)Eclipse is a multi-language software development environment comprising an integrated development environment and an extensible plug-in system...
and its plug-ins - GumTreeGumTreeGumTree is an open source scientific workbench for performing scientific experiments under a distributed network environment. It provides a multi-platform graphical user interface for instrument data acquisition, online or offline data visualisation and analysis...
Platform (scientific workbench) - HaystackHaystack (PIM)Haystack is a project at the Massachusetts Institute of Technology to research and develop several applications around personal information management and the Semantic Web. The most notable of those applications is the Haystack client, a research personal information manager and one of the first...
(information manager) - RSSOwlRSSOwlRSSOwl is a news aggregator for RSS and Atom News feeds. It is written in Java, and is built on the Eclipse Rich Client Platform which uses SWT as a widget toolkit to allow it to fit in with the look and feel of different operating systems while remaining cross-platform...
feed aggregator - uDigUDiguDig is a GIS software program produced by a community led by Canadian-based consulting company Refractions Research. It is based on the Eclipse platform and features full layered Open Source GIS...
GIS tool - TuxGuitarTuxGuitarTuxGuitar is a free, open source tablature editor, which includes basic features such as tablature editing, score editing, triplet support and the ability to import and export Guitar Pro gp3, gp4, and gp5 files. In addition, TuxGuitar can function as a basic MIDI editor using the tablature or staff...
An open source tablature editor
Recent open source efforts in the eclipse community have led to a porting of SWT (and JFace) into a widget toolkit appropriate for the web. The result has been the Eclipse RAP
Rich AJAX Platform
Rich Ajax Platform Project is an open-source software project under the Eclipse Technology Project which aims to enable software developers to build Ajax-enabled rich Internet applications by using the Eclipse development model, plugins and a Java-only application programming interface...
, which combines the qooxdoo
Qooxdoo
qooxdoo is an open source Ajax web application framework. It is an LGPL- and/or EPL-licensed multipurpose framework that includes support for professional JavaScript development, a graphical user interface toolkit and high-level client-server communication.- Framework :qooxdoo is entirely...
AJAX library with the SWT API. Like other Java AJAX
Ajax
- Mythology :* Ajax , son of Telamon, ruler of Salamis and a hero in the Trojan War, also known as "Ajax the Great"* Ajax the Lesser, son of Oileus, ruler of Locris and the leader of the Locrian contingent during the Trojan War.- People :...
projects (such as Echo2
Echo (framework)
Echo is a web application framework that was created by the company NextApp. It originally started as a request-response web application framework that leveraged the Swing object model to improve the speed of application development...
, Vaadin
Vaadin
Vaadin is an open source Web application framework for rich Internet applications. In contrast to JavaScript libraries and browser-plugin based solutions, it features a server-side architecture, which means that the majority of the logic runs on the servers. Ajax technology is used at the...
and Google Web Toolkit
Google Web Toolkit
Google Web Toolkit is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. Other than a few native libraries, everything is Java source that can be built on any supported platform with the included GWT Ant build files...
), the usage of the SWT API allows developers to quickly develop applications for the web in much the same way as they would for the desktop.
External links
- SWT main page
- Further information on SWT
- Information on Eclipse, including SWT information within a "platform plug-in developer guide"
- SWT Javadoc API documented at eclipse.org
- SWT tutorial and general documentation about eclipse
- Downloadable SWT Javadocs