Advantages and disadvantages of AWT/SWING/SWT in Java GUI programming

Source: Internet
Author: User
Tags postgresql



AWT is the abbreviation for the abstract window Toolkit (Abstraction Windows Toolkit), which is the earliest and original development kit that Sun has dedicated to Java GUI programming to build and set up the Java graphical user interface, This toolkit provides a set of interfaces that interact with the local graphical interface. The graphical functions in AWT have a one by one correspondence with the graphical functions provided by the operating system (peers). That is, when we use AWT to build a graphical user interface, we are actually using the graphics library provided by the operating system. However, the functionality that exists on one platform may not exist on the other because the functionality provided by the graphics libraries of different operating systems is not exactly the same. This results in some applications having a very beautiful interface when testing, and may become "miserable" once ported to other operating system platforms. In order to implement the Java language "compile once, run everywhere", AWT had to sacrifice functionality to achieve its platform independence, and its graphics capabilities were fixed to the intersection of the graphical functions provided by various general-purpose operating systems. Because AWT relies on local methods to implement its functions, AWT components are often referred to as heavyweight components.

AWT is a tool set that sun does not recommend. However, it has its own advantages in many non-desktop environments, such as mobile or embedded devices:

1. Less memory: The development of GUI programs running in a limited environment is appropriate.

2. Fewer boot events: Because AWT components are implemented locally by the operating system. The vast majority of binary code is already preloaded as the system starts, which reduces its startup events.

3. Better response: Because the local component is rendered by the operating system.

4. Mature and Stable: able to work properly and rarely crash your program.

But there are two sides to things, and AWT has many drawbacks:

1. Fewer component types: tables and trees these important components are missing. They are commonly used in desktop applications.

2. Lack of rich component features: The button does not support pictures.

3. No extensibility: The components of AWT are local components. The AWT class instance in the JVM is actually just a reference to the local component. The only extension point is the AWT's canvas component, which creates a custom component from scratch. However, it is not possible to inherit and reuse an existing AWT component


Swing is a new graphical interface system built on AWT that is part of JFC (Java Foundation Class) and an attempt to solve the AWT shortcomings. It provides all the functionality that AWT can provide and greatly expands the functionality of AWT with pure Java code. All swing components are actually part of the AWT. The terminology used by Swing for peer-based components is heavyweight, and the terminology used for simulated components is lightweight. In fact, Swing can support a mix of heavyweight and lightweight components in a GUI, but it is generally referred to as a lightweight component.

Swing is the most powerful GUI toolset in the three, and it is also a set of GUI tools recommended by Sun, and with several revisions and extensions, today's swing has a clear advantage in some areas:

1. Rich component types: Swing offers a very wide range of standard components. These components are as rich as SWT. Based on its good scalability, swing offers a large number of third-party components in addition to standard components. Many commercial or open-source swing component libraries are readily available after years of development.

2. Rich component features: Swing not only includes features on all platforms, it also supports adding additional features based on the platform the program is running on. The swing component features follow specific principles and are easy to scale, thus providing more functionality than SWT and AWT.

3. Good component API Model support: Swing follows the MVC pattern, which is a very successful design pattern. Its API is mature and well designed. After years of evolution, swing component APIs have become more powerful, flexible and scalable. Its API design is considered to be one of the most successful GUI APIs. More object-oriented than SWT and AWT, but also more flexible and extensible.

4. Standard GUI library: Swing and AWT are standard libraries in the JRE. Therefore, you do not have to distribute them separately with your application. They are platform-independent and do not have to worry about platform compatibility.

5. Mature and Stable: because it is pure Java implementation, there will be no SWT compatibility issues. Swing has the same performance on every platform, with no noticeable performance differences.

6. Scalability and flexibility. Swing is completely implemented by Java code. Swing's MVC-based architecture makes it possible to leverage Java as an object-oriented language. It provides overall good performance.

Of course, swing has a lot of shortcomings: for example, Swing has more memory consumption than AWT and SWT. Swing implements all of its own components. Therefore, it loads a large number of classes at run time. At run time, Java creates small objects on the heap, resulting in additional heap space consumption. Many small objects are difficult to recycle effectively by garbage collection mechanisms. As a result, swing applications often cause performance degradation due to the inability to reclaim redundant objects in a timely manner.


SWT is the abbreviation for Standard Widgettoolkit, a new GUI library built by IBM to try to completely solve the many problems that AWT and swing bring, providing a richer set of components than AWT. SWT is as painful as Swing. Java code simulates some platform-missing components, but SWT is a low-level GUI toolkit compared to the AWT concept, in the process of building SWT, the builders learned a lot from the AWT and Swing implementations, They try to build a system that combines the advantages of both without the disadvantage of both. Thus SWT can be said to be the fusion of AWT and swing.

SWT has the following advantages:

1. Rich component types: SWT provides a wide variety of components, from basic components such as buttons and labels to advanced tables and trees.

2. Relatively rich component features: Although SWT follows the maximum common multiple principle, it has redesigned support for more component features in a simulated manner. Therefore, compared with AWT, it has a relatively rich component characteristics.

3. Faster response time: Based on the same reasons as AWT, the SWT component wraps the local components and renders them by the operating system. The operating system typically optimizes rendering processing, saving GUI binaries as a standard library, reducing memory usage, and improving response performance.

4. Less memory consumption.


1. Not in the standard library of the JRE. It must therefore be bundled with the program and create a separate installer for each operating system that you want to support.

2. Not mature and stable. SWT is considered unstable due to some of its design flaws, such as resource management, Windows friendly, and so on. It can perform well on windows, but it is often unstable and prone to crashes on other operating systems. This is largely because it gives resource management to developers to handle, and not all developers are able to handle it correctly.

3. Low performance on non-Windows platforms 4. No look andfeel support. and AWT for the same reason.

4. Non-expandable.

In summary, the toolkit for GUI programming is selected according to the specific project: If you need to run a GUI program with low memory, using AWT will be a good choice, but if you consider only the portability of the platform, you can take precedence swt/swing

Advantages and disadvantages of AWT/SWING/SWT in Java GUI programming

Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Related Article

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: 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.