o7planning

Which Platform Should You Choose for Developing Java Desktop Applications?

  1. Introduction
  2. Programming Java Desktop Application
  3. Eclipse Technology
  4. RCP do what?
  5. RAP do what?
  6. RAP and RCP - Why is the same code?
  7. You should start from?

1. Introduction

In fact, there are some common questions with Java:
  • What solution should I choose to programme a Desktop application?
  • Is there any solution for programming a website whose interface is alike Desktop application's?
Trong tài liệu này tôi sẽ trả lời tổng quan về câu hỏi trên đồng thời có các giải pháp giúp bạn làm được điều đó.
Desktop Application:
This is a desktop application written in Java Swing:
Web Application:
And this is a Web application whose interface is alike a Desktop application's, and it is written on Eclipse RAP:

2. Programming Java Desktop Application

In fact, to programme a Desktop application you have 2 choices:
  • Use Swing - is a integrated library available on JDK and able to run on every different operating systems (Window, Unix, Mac OS,..)
  • Use SWT - is a library for programming Desktop applications and is developed by IBM. It is able to run on every different operating systems (Window, Unix, Mac OS,..)
This is an image of a Desktop application written with SWT and run on different operating systems.
This is an image of a Desktop application written with Swing. With a default "Look And Feel", it seems foolish. In programme, you can choose another L-A-F to get an interface similar with Windows or Linux if you want.
Swing
AWT (Abstract Window Toolkit) - is a library package developed for Desktop programme available in JDK. However, regrettably, it does not work as well as expected on different operating systems. This is the reason why Swing was born and replaced AWT in order to ensure that it runs well on different operating systems.
Swing builds graphical interface totally by Java and runs on every operating system. It does not replace AWT, but inherits from AWT instead. This is its weakness that makes programmers confused. A large number of classes owned by AWT have not been used, or become classes inherited by Swing's classes. In my opinion, this makes Swing is not appreciated.
SWT (Standard Widget Toolkit)
SWT (Standard Widget Toolkit) is a programming library for Desktop applications developed by IBM. It does not totally develop graphics with only Java. When running on an operating system, it manages to make use of graphical interfaces of that operating system (Button, Label,...) and creates only component graphics that has not existed in that operating system with Java.
When programming SWT, you should choose Eclipse IDE for the best. Eclipse can integrate with WindowBuilder plugin to help drag and drop interface components easily. WindowBuilder used to be a commercial product, but now it is free when integrated with Eclipse.
Compare SWT and Swing
Swing is a pure Java library. After you finished programming the application, you can set up Look And Feel to get an interface similar to Windows or Linux or Mac Os. Some Look And Feels are available on JDK, so you can use or buy L-A-F. Thus, you run a Swing application on the Windows platform on which display interface belongs to Linux, Mac Os,...
This is an introduction link of pretty L-A-F:
SWT - This library is not written completely by Java. When running on an operating system, it tries to make use of component libraries of that operating system (for example, it makes use of Buttons, Labels, Frames, etc) and only use Java for drawing components if they are unavailable on the operating system. Therefore, as for speed, SWT is faster than Swing.
To SWT, we don't have the concept of Look And Feel as to Swing. When you run the application on the platform of any operating system, the interface is characterized by that operating system.
Compare application performance:
You should choose SWT or Swing?
I think that you should choose SWT for programming a Desktop application because it is a library package with a plentiful supply of different interface components. Moreover, it was born after Swing, so it is the result of studying and remedying weaknesses of Swing.
SWT with expanding library packages is being developed, for example:
Eclipse develops a new platform named as RAP (Remote Application Platform) - RAP allows you to programme applications whose interfaces are alike Desktop applications' and which use familiar classes in SWT. Thus, you can write an application which can run both on the web platform and Desktop one. This is a strength if you choose SWT.
Let's see a Demo program written with RAP:

3. Eclipse Technology

We need to have an overview of technology of Eclipse
RCP is a Platform based on SWT library for programming Desktop applications . Running on different operating systems.
(More details RCP below.)
RAP (Remote Application Platform): is a Platform using RWT library for programming applications running on Web like the Desktop application.
  • RWT (RAP Widget Toolkit) is a library package whose classes' name is the same as SWT' s. It has similar methods helping you programme RAP applications running on Web. Thank to this characteristic, with only a source code, you can run the application on the Desktop platform or Web one.
RAP runs well on different browsers.
Tabris - is a library package writing Mobile applications, and able to operate on different Mobile types.

4. RCP do what?

RCP (Rich Client Platform): A Platform using SWT library for programming Desktop applications . Running on different operating systems, It is a platform created Eclipse IDE
So RCP is a Platform using SWT as the basis of building. You can use RCP Platform to programme Desktop applications.
The below image illustrates a simple application (Only use SWT, but not advanced things of RCP Platform):
Platform RCP has built a platform allowing you to programme complicated structural interfaces like IDEEclipse. It includes the systems of Menu, Toolbar, View, Editor,...
RCP also allows you to develop Plugin integrated in Eclipse that you are using.

5. RAP do what?

RAP (Remote Application Platform): is a Platform using RWT library to programme applications running on Web like applications of Desktop.
  • RWT (RAP Widget Toolkit) is a set of library with classes whose names are the same as those of classes of SWT and whose methods are similar. This helps you programme RAP applications on Web. Since this feature needs only 1 source code, you can run the application as an application of Desktop or on Web.
Like RCP, RAP is a Platform which allows us to create applications whose interfaces are as complicated as those of IDE Eclipse.
Like RCP, RAP is a Platform which allows us to create applications whose interfaces are as complicated as those of Eclipse IDE.

6. RAP and RCP - Why is the same code?

This is the structure of two Platform:
  • RCP based on SWT (Standard Widget Toolkit)
  • RAP based on RWT (RAP Widget Toolkit)
This is an example of code to add a Button to a Composite:
** MyApplicationWindow **
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;

public class MyApplicationWindow  {

    .......

   protected void createContents() {
       .......

       Composite composite = new Composite(shell, SWT.NONE);
       composite.setLayout(new GridLayout(1, false));
      
       Button btnMyButton = new Button(composite, SWT.NONE);
       btnMyButton.setText("My Button");
   }

}
Both SWT and RWT use org.eclipse.swt.widgets.Button class to create a button.

Code of Button class of SWT (run on desktop) is obviously different from code of Button class of RWT (inherently run on WEB).
  • Button class of SWT is packed in jar file named org.eclipse.swt_*.jar
  • Button class of SWT is packed in jar file named org.eclipse.rap.rwt_*.jar
Target Platform is a library environment where you can declare.

You can declare two Target Platforms. One includes RCP libraries, and another includes RAP libraries.
  • RCP Target Platform
  • RAP Target Platform
With the same code but if you run with RCP Target Platform, you will get a Desktop application; if you run with RAP Target Platform, you will get an application on Web.

Of course, RAP and RCP have some differences. No all components of SWT have equivalently on RWT, and vice versa. In specific situations, we can handle this difference. Applications which can run on both Desktop and Web are known as "Single Sourcing".

7. You should start from?

If you choose RAP-RCP programming, you will have to study SWT. This means you can easily learn about RWT.

Working with SWT means working with Widget objects (Button, Label,...) and handle Layout. WindowBuilder is a Plugin allowing us to drag & drop components on the interface and automatically generate equivalent codes.
You can reference the following document that instruct you to program SWT with WindowBuilder which is a visual tool helping drag & drop interface components easily.
After you have been fluent in programming with SWT, you can continue with RCP or RAP.
SWT:
RCP
RAP

Eclipse Technology

Show More

Java Basic

Show More