In a previous article I already introduced you to SWT Stand alone Applications. In this article we’re actually going to build one.
While SWT is integrated as part of the Eclipse plug-in API, for standalone application development it is best to develop against the SWT standalone download. This document will help you get set up.
First, download the .zip of SWT for your platform from the SWT homepage.
The SWT .zip file can then be imported into your workspace. In the File menu, choose Import and select the Existing Projects Into Workspace wizard. (In newer versions of eclipse, you can find Existing Projects Into Workspace in the General category).
The illustrations with this article come from a Linux version of Eclipse but like with Java it doesn’t matter which platform you’re using. Just like the code, the documentation is portable.
Direct the wizard to the location where you downloaded the .zip file. This will create a project called org.eclipse.swt in your workspace.
Your Java projects can then add the SWT project as a dependency. Open the properties dialog of your Java project, and on the Java Build Path page, include the org.eclipse.swt project.
With the SWT project as a dependency, you can now benefit from Eclipse features such as the Javadoc view and code assist.
Now you can run any main class in your project by selecting the class and then selecting Run > Run As > Java Application.
The Standard Widget Toolkit (SWT) is a graphical widget toolkit for use with the Java platform. It was originally developed by Stephen Northover at IBM and is now maintained by the Eclipse Foundation in tandem with the Eclipse IDE. It is an alternative to the Abstract Window Toolkit (AWT) and Swing Java graphical user interface (GUI) toolkits provided by Sun Microsystems as part of the Java Platform, Standard Edition (J2SE). Both SWING and AWT have always been criticized for their slowness. They actually ‘draw’ GUI components on screen pixel by pixel, which slows down the building up of screens.
This is different for SWT which accesses the native GUI libraries of the operating system using Java Native Interface (JNI) in a manner that is similar to those programs written using operating system-specific application programming interfaces (APIs). 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 results are Native Speed Applications for Mac, Windows and Linux. Probably the best example is the SWT Webbrowser. An SWT example which is included in the Eclipse IDE and is used by Eclipse to show its help documents.
Thanks for reading this article. If you’re interested in the details of building SWT Applications see the next article .
Eclipse is one of the most popular IDE’s. In this article we will use Eclipse to investigate an existing class from the java.text package. The class we will investigate is the DateFormat.
DateForma is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner. The date/time formatting subclass, such as SimpleDateFormat, allows for formatting (i.e., date -> text), parsing (text -> date), and normalization. The date is represented as a Date object or as the milliseconds since January 1, 1970, 00:00:00 GMT. DateFormat provides many class methods for obtaining default date/time formatters based on the default or a given locale and a number of formatting styles. The formatting styles include FULL, LONG, MEDIUM, and SHORT. More detail and examples of using these styles are provided in the method descriptions.
DateFormat helps you to format and parse dates for any locale. Your code can be completely independent of the locale conventions for months, days of the week, or even the calendar format: lunar vs. solar. Browsing the JavaDoc is always fun. But even more fun is firing up your IDE and have a look. So let’s do so!
With DateFormat chosen in the TypeHierachy I can see it inherits directly from an Abstract class named Format. (You recognize the Abstract Class by the small A in it’s upper-right corner. As you can see DateFormat is Abstract itself.
Now zoom in on the DateFormat to get the full type hierarchy:
As you can see, SimpleDateFormat inherits from DateFormat, which in turn Inherits from Format, which (like any other Object) inherits from Object.
Eclipse is an excellent tool to study existing Java Classes and their hyrarchie in comparison with other classes. You can also use this to investigate (chains of) method calls by selecting a method and choose ‘Call hierarchy’. Try this yourself and enjoy it!
Let's work smarter in the Philippines!