Java desktop development with Qt Jambi

A sophisticated alternative to GUI development with Swing and Java 2D

Qt Jambi is a new and noteworthy alternative to Swing and Java 2D for developing rich, cross-platform desktop-application interfaces. In this article JavaWorld contributor Jeff Hanson introduces the recently released Qt Jambi, explains how it works under the hood, and presents programming examples that will familiarize you with the framework's drag-and-drop API and integrated development tools.

Qt Jambi, released in early June 2007, is a development framework that integrates the Java programming language with Trolltech's popular C++ GUI development framework, Qt. Released under a dual open-source/commercial license, Qt Jambi enables Java developers using Java Standard Edition 5.0 (JSE 5.0) and later to leverage the features of the Qt framework. Along with industry-tested cross-platform support, Qt Jambi provides support for GUI development basics such as 2D and 3D graphics, drag-and-drop interobject event messaging, internationalization, SQL database access, XML and TCP/IP network protocols. A Qt Jambi Eclipse plug-in also gives you the option to access the features of Qt Jambi using Eclipse.

Download Qt Jambi
Qt Jambi is offered under a dual open source/commercial license. You can download either version from the Trolltech homepage. The open-source version is provided under the GNU General Public License and comes without support or warranty. Commercial projects are required to use the commercial version of Qt Jambi.

Qt Jambi builds on Qt's cross-platform C++ GUI foundation to ease the task of developing native look-and-feel user interfaces for most desktop platforms using Java code. As such, it is an interesting alternative to Swing and Java 2D for Java desktop development. In this hands-on introduction to Qt Jambi you will learn about Qt Jambi's development API and integrated development tools. You will be introduced to Qt Jambi's widget-based GUI framework and learn how to create a project using the Qt Designer. You will also compare Qt Jambi's signals-and-slots event handling mechanism with the Java event listener framework, get a first look at Qt Jambi's graphics rendering system, and see for yourself how it integrates with Eclipse via the Qt Jambi Eclipse plug-in.

Download Qt Jambi now if you would like to follow along with the examples.

Overview of Qt Jambi

Qt Jambi is a Java-based framework that integrates Trolltech's cross-platform C++ framework for GUI development with the Java programming language. The following features are available when developing Java desktop applications with Qt Jambi:

  • Excellent cross-platform support for 2D and 3D graphics
  • A unique interobject event communication mechanism
  • Internationalization
  • SQL database access
  • Support for XML
  • Support for TCP/IP network protocols

You can use Qt Jambi with most JVMs (Java virtual machines) subsequent to Java Standard Edition (JSE) 5.0 and Java Enterprise Edition (JEE) 5.0. Qt Jambi's tight OS integration enables you to produce Java desktop applications that mimic the native OS look and feel.

Qt meets the Java programming language

The Qt Jambi API provides a thin layer of Java code that interacts with Trolltech's natively compiled C++ libraries. This layer of Java code runs in any Java Runtime Environment (JRE) and uses the Java Native Interface (JNI) framework to communicate with the native C++ libraries.

Essentially, Qt Jambi places a Java abstraction layer over Qt's C++ libraries. To address the similarity and overlap between Qt's C++ classes and Java's core classes, Qt Jambi maps the overlapping C++ classes to corresponding Java classes. As a result, you may use standard Java constructs and operators with Qt's native abstractions. You also can intermingle Qt Jambi APIs with non-Qt Java APIs.

Table 1 shows the Qt classes that are mapped to equivalent Java core classes.

Table 1. Qt classes mapped to equivalent Java classes

Qt classJava class(es)
QCharchar and java.lang.Character

The Qt C++ API depends on an abstract value type QVariant to encapsulate many Qt value types. Because the Java language already provides a common abstract type for all classes (the common Object base class), the Qt Jambi API relies on the Object class wherever Qt C++ relies on QVariant. Qt Jambi maps C++ enums to Java enums to enforce type safety for Qt-Java enums and bit flags.

Qt Jambi includes a widget-based GUI framework that takes advantage of platform-specific extensions such as ActiveX, OpenGL, and ClearType. This framework provides native look-and-feel capabilities for Windows, Mac OS X and Linux themes.

Widgets in Qt Jambi follow a style-sheet syntax similar to HTML Cascading Style Sheets (CSS), so you can perform minor or widespread customizations by tweaking CSS-style tags and properties. You can also subclass Qt's widgets for even more look-and-feel customization and control.

Qt Jambi's GUI framework includes layout management classes that are presented in the Qt Designer tool to simplify layout when building desktop components and applications. Figure 1 shows the Layouts window in the Qt Designer tool.

Screenshot of the Layouts window in the Qt Designer tool.
Figure 1. Layouts window in the Qt Designer tool

Qt Jambi's GUI framework provides APIs for building applications with dockable components. Among other things, you can use this feature to create desktop applications with native look-and-feel docking toolbars.

1 2 3 4 5 Page 1
Page 1 of 5