Standard Widget Toolkit
   HOME

TheInfoList



OR:

The Standard Widget Toolkit (SWT) is a graphical
widget toolkit A widget toolkit, widget library, GUI toolkit, or UX library is a library or a collection of libraries containing a set of graphical control elements (called ''widgets'') used to construct the graphical user interface (GUI) of programs. Most widge ...
for use with the
Java platform Java is a set of computer software and specifications developed by James Gosling at Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cro ...
. It was originally developed by Stephen Northover at IBM and is now maintained by the
Eclipse Foundation The Eclipse Foundation AISBL is an independent, Europe-based not-for-profit corporation that acts as a steward of the Eclipse open source software development community, with legal jurisdiction in the European Union. It is an organization suppo ...
in tandem with the
Eclipse IDE Eclipse is an integrated development environment (IDE) used in computer programming. It contains a base workspace and an extensible plug-in system for customizing the environment. It is the second-most-popular IDE for Java development, and, ...
. It is an alternative to the
Abstract Window Toolkit The Abstract Window Toolkit (AWT) is Java's original platform-dependent windowing, graphics, and user-interface widget toolkit, preceding Swing. The AWT is part of the Java Foundation Classes (JFC) — the standard API for providing a graphi ...
(AWT) and
Swing Swing or swinging may refer to: Apparatus * Swing (seat), a hanging seat that swings back and forth * Pendulum, an object that swings * Russian swing, a swing-like circus apparatus * Sex swing, a type of harness for sexual intercourse * Swing ri ...
Java
graphical user interface The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, ins ...
(GUI) toolkits provided by
Sun Microsystems Sun Microsystems, Inc. (Sun for short) was an American technology company that sold computers, computer components, software, and information technology services and created the Java programming language, the Solaris operating system, ZFS, t ...
as part of the
Java Platform, Standard Edition Java Platform, Standard Edition (Java SE) is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE). The platform uses Ja ...
(J2SE). To display GUI elements, the SWT implementation accesses the native GUI libraries of the
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
using
Java Native Interface In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by native applications (programs specific to a hardwa ...
(JNI) in a manner that is similar to those programs written using operating system-specific
application programming interface An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
s (APIs). Programs that call SWT are portable, but the implementation of the toolkit, despite part of it being written in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
, is unique for each platform. The toolkit is
free and open-source software Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
distributed under the
Eclipse Public License The Eclipse Public License (EPL) is a free and open source software license most notably used for the Eclipse IDE and other projects by the Eclipse Foundation. It replaces the Common Public License (CPL) and removes certain terms relating to li ...
, which is approved by the
Open Source Initiative The Open Source Initiative (OSI) is the steward of the Open Source Definition, the set of rules that define open source software. It is a California public-benefit nonprofit corporation, with 501(c)(3) tax-exempt status. The organization wa ...
.


History

The first Java GUI toolkit was the
Abstract Window Toolkit The Abstract Window Toolkit (AWT) is Java's original platform-dependent windowing, graphics, and user-interface widget toolkit, preceding Swing. The AWT is part of the Java Foundation Classes (JFC) — the standard API for providing a graphi ...
(AWT), introduced with
Java Development Kit The Java Development Kit (JDK) is a distribution of Java Technology by Oracle Corporation. It implements the Java Language Specification (JLS) and the Java Virtual Machine Specification (JVMS) and provides the Standard Edition (SE) of the Java ...
(JDK) 1.0 as one component of Sun Microsystems' Java platform. The original AWT was a simple Java
wrapper library Wrapper libraries (or library wrappers) consist of a thin layer of code (a "shim") which translates a library's existing interface into a compatible interface. This is done for several reasons: * To refine a poorly designed or complicated interfac ...
around native (
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
-supplied) widgets such as menus, windows, and buttons.
Swing Swing or swinging may refer to: Apparatus * Swing (seat), a hanging seat that swings back and forth * Pendulum, an object that swings * Russian swing, a swing-like circus apparatus * Sex swing, a type of harness for sexual intercourse * Swing ri ...
was the next generation GUI toolkit introduced by Sun in
Java Platform, Standard Edition Java Platform, Standard Edition (Java SE) is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE). The platform uses Ja ...
(J2SE) 1.2. Swing was developed to provide a richer set of GUI
software component Component-based software engineering (CBSE), also called component-based development (CBD), is a branch of software engineering that emphasizes the separation of concerns with respect to the wide-ranging functionality available throughout a give ...
s than AWT. Swing GUI elements are all-Java with no native code: instead of wrapping native GUI components, Swing draws its own components by using Java 2D to call low-level operating system drawing routines. The roots of SWT go back to work that
Object Technology International Object Technology International (OTI) was founded in Ottawa, Ontario (Canada) in 1988 and acquired by IBM in 1996. OTI, in conjunction with the IBM development lab in Cary, NC, developed the VisualAge line Smalltalk Smalltalk is an object-o ...
(OTI), did in the 1990s when creating multiplatform, portable, native widget interfaces for
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan ...
, 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 An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools ...
(IDE) written in Smalltalk. They decided to open-source the project, which led to the development of
Eclipse An eclipse is an astronomical event that occurs when an astronomical object or spacecraft is temporarily obscured, by passing into the shadow of another body or by having another body pass between it and the viewer. This alignment of three c ...
, intended to compete against other IDEs such as
Microsoft Visual Studio Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platforms such ...
. Eclipse is written in Java, and IBM developers, deciding that they needed a toolkit that had "native
look and feel In software design, the look and feel of a graphical user interface comprises aspects of its design, including elements such as colors, shapes, layout, and typefaces (the "look"), as well as the behavior of dynamic elements such as buttons, box ...
" and "native
performance A performance is an act of staging or presenting a play, concert, or other form of entertainment. It is also defined as the action or process of carrying out or accomplishing an action, task, or function. Management science In the work place ...
", created SWT as a Swing replacement.


Design

SWT is a wrapper around native code objects, such as
GTK GTK (formerly GIMP ToolKit and GTK+) is a free and open-source cross-platform widget toolkit for creating graphical user interfaces (GUIs). It is licensed under the terms of the GNU Lesser General Public License, allowing both free and propriet ...
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 Erich Gamma is a Swiss computer scientist and one of the four co-authors (referred to as "Gang of Four") of the software engineering textbook, '' Design Patterns: Elements of Reusable Object-Oriented Software''. Gamma is an expert in the Eclipse ...
of
Design Patterns ''Design Patterns: Elements of Reusable Object-Oriented Software'' (1994) is a software engineering book describing software design patterns. The book was written by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, with a forewo ...
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 (born May 19, 1955) is a Canadian computer scientist, best known as the founder and lead designer behind the Java programming language. Gosling was elected a member of the National Academy of Engineering in 2004 for the conception ...
, the creator of the Java language, has argued that SWT is too simple, and is a difficult toolkit to port to new platforms for the same reason that AWT once had 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 (MVC) is a software architectural pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements. This is done to separate internal representations of info ...
(MVC) architecture used in Swing and many other high level GUI toolkits, the
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." The Standard Widget Toolkit (SWT) is an open source widget toolkit for Java designed to provide ...
library, which is developed as part of the same Eclipse project, does provide a
cross-platform In computing, cross-platform software (also called multi-platform software, platform-agnostic software, or platform-independent software) is computer software that is designed to work in several computing platforms. Some cross-platform software ...
, higher-level MVC abstraction atop 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 feel In software design, the look and feel of a graphical user interface comprises aspects of its design, including elements such as colors, shapes, layout, and typefaces (the "look"), as well as the behavior of dynamic elements such as buttons, box ...
'' 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
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and la ...
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, which supports the ability to change the look and feel of the running application with "pluggable looks and feels". These enable emulating the native platform user interface using themes, 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 is a deprecated software framework created by Microsoft that adapts its earlier Component Object Model (COM) and Object Linking and Embedding (OLE) technologies for content downloaded from a network, particularly from the World Wide We ...
objects on
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for ...
.


Programming

The following is a basic
Hello World ''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich ...
program using SWT. It shows a window (''Shell'') and a label. import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class HelloWorld Contrary to
Swing Swing or swinging may refer to: Apparatus * Swing (seat), a hanging seat that swings back and forth * Pendulum, an object that swings * Russian swing, a swing-like circus apparatus * Sex swing, a type of harness for sexual intercourse * Swing ri ...
, a ''Display'' class is necessary to access the underlying
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
, 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 programs may be exposed to platform-specific bugs. SWT exposes programs 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. , SWT supports these platforms and/or GUI libraries: *
Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for se ...
: **
Win32 The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. The name Windows API collectively refers to several different platform implementations th ...
**
Windows Presentation Foundation Windows Presentation Foundation (WPF) is a free and open-source graphical subsystem (similar to WinForms) originally developed by Microsoft for rendering user interfaces in Windows-based applications. WPF, previously known as "Avalon", was initia ...
(WPF), under development *
Unix-like A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
:
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, whi ...
,
FreeBSD FreeBSD is a free and open-source Unix-like operating system descended from the Berkeley Software Distribution (BSD), which was based on Research Unix. The first version of FreeBSD was released in 1993. In 2005, FreeBSD was the most popular ...
: **
GTK GTK (formerly GIMP ToolKit and GTK+) is a free and open-source cross-platform widget toolkit for creating graphical user interfaces (GUIs). It is licensed under the terms of the GNU Lesser General Public License, allowing both free and propriet ...
*
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and la ...
: **
Cocoa Cocoa may refer to: Chocolate * Chocolate * ''Theobroma cacao'', the cocoa tree * Cocoa bean, seed of ''Theobroma cacao'' * Chocolate liquor, or cocoa liquor, pure, liquid chocolate extracted from the cocoa bean, including both cocoa butter an ...
, SWT 4.7.3a (and 4.8M6) is officially compatible with the following operating systems (graphic library or similar if explicitly required / processors): * Microsoft Windows (x86 and x86_64) * Linux (GTK / PPC64 and PPC64LE) * macOS (Cocoa / x86_64)
Windows XP Windows XP is a major release of Microsoft's Windows NT operating system. It was release to manufacturing, released to manufacturing on August 24, 2001, and later to retail on October 25, 2001. It is a direct upgrade to its predecessors, Wind ...
has historically been supported. Older version additionally officially supported
s390 The IBM System/390 is a discontinued mainframe product family implementing the ESA/390, the fifth generation of the System/360 instruction set architecture. The first computers to use the ESA/390 were the Enterprise System/9000 (ES/9000) ...
,
Solaris 11 Solaris may refer to: Arts and entertainment Literature, television and film * ''Solaris'' (novel), a 1961 science fiction novel by Stanisław Lem ** ''Solaris'' (1968 film), directed by Boris Nirenburg ** ''Solaris'' (1972 film), directed by ...
(SPARCv9),
Solaris 10 Solaris is a proprietary Unix operating system originally developed by Sun Microsystems. After the Sun acquisition by Oracle in 2010, it was renamed Oracle Solaris. Solaris superseded the company's earlier SunOS in 1993, and became known fo ...
(x86_64),
HP-UX HP-UX (from "Hewlett Packard Unix") is Hewlett Packard Enterprise's proprietary implementation of the Unix operating system, based on Unix System V (initially System III) and first released in 1984. Current versions support HPE Integrity Se ...
(ia64),
AIX Aix or AIX may refer to: Computing * AIX, a line of IBM computer operating systems *An Alternate Index, for a Virtual Storage Access Method Key Sequenced Data Set * Athens Internet Exchange, a European Internet exchange point Places Belgiu ...
(PPC and PPC64).


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
benchmarking Benchmarking is the practice of comparing business processes and performance metrics to industry bests and best practices from other companies. Dimensions typically measured are quality, time and cost. Benchmarking is used to measure performanc ...
of SWT and Swing, which concluded that SWT should be 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 users 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, in contrast to the standard Java practice of automatic garbage collection. SWT objects must be explicitly deallocated using the dispose method, which is analogous to the
C language C (''pronounced like the letter c'') is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities ...
's free. If this is not done,
memory leak In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released. A memory leak may also happen when an object ...
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. These objects are not tracked by the Java JVM, so it cannot track whether or not such objects are in use, and thus cannot garbage collect them at a suitable time. In practice, the only SWT objects which a program must explicitly dispose are the subclasses of Resource, such as Image, Color, and Font objects.


Development

There is some development activity to enable combining Swing and SWT. Two different approaches are being attempted: * ''SwingWT'' is a project to provide an alternative Swing implementation. It 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 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 programming language D called DWT. Since then, the project supports Windows 32-bit, and Linux GTK 32-bit for SWT-3.4. The DWT project also has an addon package that contains a port of
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." The Standard Widget Toolkit (SWT) is an open source widget toolkit for Java designed to provide ...
and Eclipse Forms. With
JavaFX JavaFX is a software platform for creating and delivering desktop applications, as well as rich web applications that can run across a wide variety of devices. JavaFX has support for desktop computers and web browsers on Microsoft Windows, Linu ...
becoming part of the Java SE platform there has been interest in developing a backend for SWT that relies on JavaFX in a similar way to SWTSwing relies on Swing. A prominent project trying to achieve that was ''SWT on JavaFX'' that became part of ''e(fx)clipse'' in 2014.


Uses

Applications (alphabetically sorted) using SWT include: *
Apache Directory Apache Directory is an open source project of the Apache Software Foundation. The Apache Directory Server, originally written by Alex Karasulu, is an embeddable directory server entirely written in Java. It was certified LDAPv3-compatible by T ...
Studio, an LDAP browser–editor *
Eclipse An eclipse is an astronomical event that occurs when an astronomical object or spacecraft is temporarily obscured, by passing into the shadow of another body or by having another body pass between it and the viewer. This alignment of three c ...
and its plug-ins *
GumTree Gumtree.com, known as Gumtree, is a British-based online classified advertisement and community website based at Hotham House, Richmond, London. Classified ads are either free or paid for depending on the product category and the geographical ...
Platform, scientific workbench *
Haystack Hay is grass, legumes, or other herbaceous plants that have been cut and dried to be stored for use as animal fodder, either for large grazing animals raised as livestock, such as cattle, horses, goats, and sheep, or for smaller domesticated ...
, information manager * IBM
Rational Software Rational Machines is an enterprise 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 Iterative and in ...
products: Rational Application Developer, Rational Software Architect, Rational Team Concert and others. * IBM Lotus software products: Lotus notes, Notes, Lotus Sametime, Sametime, IBM Lotus Symphony, Symphony, and Lotus Expeditor, Expeditor * Studio 3T, GUI client for MongoDB database * RSSOwl, feed aggregator * SmartGit, a Git (software), Git, Mercurial, and Apache Subversion (SVN) client * TuxGuitar, an open source tablature editor * uDig, GIS tool * Vuze, formerly named Azureus 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 Remote Application Platform (RAP), which combines the qooxdoo Ajax library with the SWT API. Like other Java Ajax (programming), Ajax projects (such as Echo (framework), Echo2, Vaadin and Google Web Toolkit), the usage of the SWT API allows developing applications quickly for the web in much the same way as for the desktop.


See also

* List of widget toolkits


Notes


References

* * * * * *


External links

* {{Java desktop Eclipse (software) Eclipse software Eclipse technology Free computer libraries Java (programming language) libraries Java APIs Java platform Software using the Eclipse license Widget toolkits