What is the difference between AWT and SWT?

Source: Internet
Author: User

From http://www.jguru.com/faq/view.jsp? Eid = 507891

Answer

SWT (Standard Widget Toolkit) is a completely independent graphical user interface (GUI) toolkit from IBM. They created it for their new eclipse integrated development environment (IDE ).

IBM began work on SWT a few years ago, because swing was still immature and didn't perform well. They decided to create a new toolkit to provide better performance using native widgets.

The basic concepts behind SWT and AWT are fairly similar, but the implementations are quite different:

  • Users write programs that use the AWT or SWT libraries for GUI widgets.
  • AWT and SWT delegate widget control to the native components on the user's machine.

The AWT way

The big difference is how the two toolkits use the native components. in AWT, native "peer" code, written in a language like C or C ++, is used to control the real widgets on the system. if you're running on Windows, this peer Code uses MFC or Win32 callto display widgets. on other platforms, the native GUI callfor their operating system/window manager are used.

Each Java Runtime Environment (JRE) distribution provides a unique set of peers for the target platform. The Java classes stay the same; the native code changes.

AWT implementations suffer three key problems because of this structure:

  • Not all platforms support the same widget set, so a "least common denominator" effect occurs. AWT only provides a very basic set of components, ones that all modern platforms provide.
  • If you want to provide a component that exists on some platforms but not others, you must code it entirely in Java (or use JNI, which wowould limit that code to one platform ). this is the implementation strategy of swing -- Swing components are written in Java, drawing the new components like trees and tables using AWT graphics CILS.
  • A good chunk of the GUI logic is buried in C or C ++ code (That isn' t delivered with the normal Java SDK distribution ). this can make it difficult to find errors that occur because you can't see this code executing in a debugger.

The SWT way

IBM took a different approach. Rather than write the peers in native code, they wrote a thin Java Native Interface (JNI) LayerFor each platformThat exposes the gui api of that platform. Java code, similar to the AWT native-code peers, uses CALS to the native API for that platform to control the widgets.

With SWT, some of the library Java class implementations vary between platforms, rather than distributing native peer code.

This solves the three abve problems with AWT:

  • (For the first two problems) if some platforms support a widget that others don't, the widget can be madeNativeOn those platforms andEmulatedOn the others. in both cases, only Java code has to be written to take advantage of it. for example, Windows provides trees and tables, so SWT's Java code callthe MFC/Win32 libraries to display the trees and tables. if another platform didn't provide trees or tables, the Java code for that platform cocould draw them.

    • A key advantage here is that a tree or tableReallyIs the platform's tree or table on platforms that support it natively. Swing hasEmulateThe tree or table, and it's very hard to get it exactly right. not to mention, upgrade to Windows XP. and the trees and tables will actually look different if you use SWT. using swing, they all still look like Windows 9x/2000.
  • All of the logic added for SWT is written in Java; there's no significant C/C ++ code. debugging the toolkit becomes easier. (and it's easier to tell exactly what the toolkit is doing "behind the scenes ").

Applications vs. ide

SWT was designed for useIn the Eclipse IDE. It wasn' t initially intended to be used for standalone applications. however, later this year (2001), IBM plans to open-source eclipse and SWT, and you can use it for applications if you wowould like. building guis using SWT feels a little different than AWT, but there are definitely some similarities. watch for SWT tutorials at the eclipse web site (http://www.eclipse.org /)

If you write plugins for the Eclipse IDE, youShocouldUse SWT. Yes, it's another API to learn, but you must consider it from the end-user's point of view. SWTIsThe GUI toolkit used for eclipse, and eclipseIsAnIntegratedDevelopment Environment. Using SWT keeps everything looking and feeling the same.

For more information

A more detailed discussion of SWT architecture appears at http://www.eclipsecorner.org/articles/Article-SWT-Design-1/SWT-Design-1.html.

For other details on Eclipse and SWT, please visit http://www.eclipse.org /.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.