The Java Developer's Guide to EclipseThe Java Developer's Guide to Eclipse

Chapter 33, Swing Interoperability, is for those not quite ready to jump in and rewrite their Swing-based development tools or applications based on SWT (see Chapter 14). There are a various reasons for choosing an SWT–Swing hybrid approach: time-to-market considerations, for example, or the desire to create a prototype that demonstrates the value of Eclipse integration. In either case, the goal is to add your existing function to the Eclipse Platform with minimal changes to your existing code base while at the same time providing some level of integration with Eclipse that affords a good end-user experience.

Two examples complement Chapter 33:

  1. The first example, described below, is Windows-specific and defined in the project com.ibm.jdg2e.swt_swing.embed.converter. This plug-in defines a "Volume Converter" that demonstrates how to embed an AWT/Swing application.
  2. The second example is defined in the project com.ibm.jdg2e.swing.external.launch. It is a hybrid application that incorporates a Swing editor in a launch-and-edit scenario, which keeps the Eclipse workspace synchronized with the file system changes made by the editor. The launch-and-edit example is provided as an alternative implementation for those platforms where embedding is not yet supported.

Running the Example

To launch the first example, select Run > Run As > Eclipse Application and then open the converter from the runtime Workbench's Window > Show View > Other... > JDG2E > Volume Converter menu choice.

Swing volume converter view

Roadmap of the Example

  1. The example starts with a standard view part implemented in the class EmbeddedSwingConverterView.
  2. The EmbeddedSwingConverterView creates a user interface using an SWT Composite that can accept Swing widgets.
  3. The SWT Composite is used as the base for the creation of a Swing component, this is done using VolConverter, which calls other classes to build the Swing-based UI.
  4. Actions in the view part are used to control the behavior of the Swing-based components.

Class (All) Description
EmbeddedSwingConverterView The EmbeddedSwingConverterView is an Eclipse view part that can host a mix of SWT and Swing components. simple example of a Swing application that provides a text editor for files of type .abc.
VolConverter Component that creates a Swing user interface on top of the SWT composite that can support Swing widgets.

© Copyright International Business Machines Corporation, 2003, 2004, 2006. All Rights Reserved.
Code or samples provided herein are provided without warranty of any kind.