Using JOGL in AWT SWT and Swing

From JogampWiki
Revision as of 22:17, 27 January 2011 by Wwalker (talk | contribs) (Created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

You can use JOGL with three different Java window toolkits: AWT, SWT, and Swing. This page shows examples of all three systems, plus variations on each.

How to choose

Usually the windowing system you use for JOGL is dictated by the requirements of your application. If you're writing an Eclipse-based application, it makes sense to use SWT, since it's the native windowing system of Eclipse. Otherwise, Swing is probably the way to go. If you want to wrap native controls instead of drawing in software like Swing, and you're not writing an Eclipse app, AWT is your choice.

Base class

First, a base class that we'll use in all five examples. This class abstracts out all the pure OpenGL calls that don't depend on the choice of windowing toolkit.


JOGL in AWT

The Abstract Window Toolkit (AWT) was Java's first window toolkit. It's a thin layer over each platform's native window toolkit.

JOGL in SWT

The Standard Widget Toolkit (SWT) is a thin layer over each platform's native window toolkit. SWT is the toolkit used in Eclipse, so it makes sense to use SWT in Eclipse-based applications.

JOGL in SWT using the SWT-AWT bridge

The SWT-AWT bridge was created to allow SWT applications to use the AWT GLCanvas. You should use this if you have problems with the SWT GLCanvas.

JOGL in Swing

Swing is the primary Java window toolkit since Java 1.2 in 1997. It's based on AWT at a low level, but draws all its own controls instead of wrapping native controls.

JOGL in Swing using the GLJPanel

In cases where the AWT GLCanvas has problems integrating with Swing components correctly, the GLJPanel can be used instead. It's supposed integrate 100% correctly into Swing, but with lower performance.