# Java Notes

# GUI Alternatives

## The problems

After a little experience, it isn't difficult to build a Graphical User Interface (GUI) in Java, but it is hard to get something that is easy to write and maintain, and looks good. Many styles of GUI programming simply don't scale well.

### Separation of concerns

- BAD: Mix logic and interface. This is a typical style for small student programs. The code to perform the action of a button is in the button's action listener. This does NOT scale well as programs get bigger.
- GOOD: Separate GUI from logic. As programs grow larger, it's essential to separate the GUI interface processing from the logic. This is easy to do by putting the interface and logic in separate classes. Some GUI generators below help accomplish this.

### Some GUI programming alternatives

Some of the main alternatives to simple programming that are getting the most attention are:

- Matisse in Netbeans - WYSIWYG GUI editor
- JFormDesigner - WYSIWYG GUI editor that supports JGoodies FormLayout, TableLayout, and GridBagLayout. 65 Euros and up.
- BuoyBuilder- WYSIWYG GUI editor based on Buoy toolkit. Free to $299, depending.
- Visual Editor for Eclipse.
- SwiXML - XML representation of GUI.
- JAXX - XML based GUI representation. They have a nice page pointing to the competitors (Competition)

Disucssion of implementing a GUI in code vs XML is at Resource based GUIs vs. Code Generation.

F3 is a programming language that generates Java Byte Code, and has an interesting approach to generating a GUI. The F3 Programming Language is probably not the best link to it, but it's so early that there doesn't seem to be much mature documentation on it. An interesting idea anyway.

### More alternatives

1. Use Drag and Drop GUI editors. Many IDEs (NetBeans, Eclipse (only SWT), JBuilder, ...) have GUI editors and there are also numerous standalone products. They don't always enforce separation of interface and logic, but it's usually easy to do. I've used NetBeans with good results.

   The new NetBeans Matisse project looks promising.

2. Alternatives to Swing and AWT. You don't have to use the Java GUI libraries to build your GUI. There are alternatives.
   - SWT - IBM's alternative to Swing. An interesting discussion can be found at www.hacknot.info/hacknot/action/showEntry?eid=74.
   - Buoy - (buoy.sourceforge.net/) - "Buoy is a library for creating user interfaces in Java programs. It is built on top of Swing, but provides completely new classes to represent UI components. Its advantages include a simpler API, a more powerful event handling mechanism, and much more."

     Public domain. Looks interesting. It's educational to read the About Buoy document, which points out a number of problems and inconsistencies in Swing.

     BuoyBuilder (/www.buoybuilder.com) can be used to build Buoy applications. It's free for non-commercial projects.

3. Use Flash or JavaScript+HTML for the GUI. Why should your interface be in Java? You can use existing GUI technologies like Flash or JavaScript+HTML (check out Sun's LiveConnect, which should already be installed with your version of Java) to interact with your Java program. Apparently this sounds better in principle that in practice. I'm not away of many users of this approach.
4. Describe the GUI in some other language (eg, XML). This approach is described below in the XUL (XML User interface Language) philosophy.

## The XUL philosophy

Everyone says that user interfaces should be separated from the logic of a program. One of the most promising approaches is to represent the GUI in a markup language (think HTML forms with a full set of widgets). The Mozilla XUL group (see link below) has been one of the most active in proposals in this area, altho their actual offerings don't seem quite ready for prime time. Some good links to start with follow.

- XML User Interface Language (XUL) Links (xul.sourceforge.net/links.html)
- JDesktop Network Components shows that Sun is thinking about these issues.
- XUL News Wire has links to a lot of approaches.

I've tried SwixML and Thinlet, both of which read an XML file to build the GUI at execution time. On small test programs I really liked them. They're not quite mature yet (eg, weak documentation). SwixML has a number of users and a helpful mailing list.

Take a look at XUL and Java. It seems obvious to me for some comments by Karsten Lentzsch of JGoodies for some criteria that might be used in evaluating this not-entirely-obvious technology.

Microsoft announced XAML, an XML description of user interfaces (and much more) for the upcoming Avalon system (see below). It looks like Microsoft may take the lead in this area; and I wouldn't be surprised if their work sets the future direction. Java's Java Desktop Network Components (JNDC) (see www.javadesktop.org/articles/JDNC/index.html, Java Desktop Network Components) shows some philosophical interest in XUL.

## XUL based and other GUI generator schemes

I didn't look closely at most of these, but this gives the idea that a lot of people would like to make this work. My goal is to find something that makes simple programs simpler, ie something for student programs. Some of these frameworks may be very good for simplifying large programs, but don't seem simpler for small programs.

SwixML | www.swixml.org - I've tried SwixML with mixed feelings. On one hand, it forced a very nice separation of presentation from other concerns, and it worked well. One the other hand, there was a lack of documentation and error reporting that made development very time-consuming. If you put in the time to become an expert, this may be a rewarding approach. Open source.
Thinlet | www.thinlet.com - Open source. The author's philosophy is aim it at handheld devices. This is worth a look if you're interested in something small, and not based on Swing. I liked the previous version, but haven't looked at the new version.
SwingML | swingml.sourceforge.net - Open source. Looks good, but it isn't obvious how to connect the GUI to a Java application. Seems to be oriented toward Applet server communication. Nice demo. Last update Aug 2003.
CUF | cuf.sourceforge.net/ - CUF (Client Utilities and Framework) provides an XML representation of the GUI that will work with either Swing or .NET. Interesting, but where's the documentation? Open-source.
AUIML | www.alphaworks.ibm.com/tech/auiml (Abstract User Interface Markup Language Toolkit). Includes an interface builder, and same interface can be used either as Swing or HMTL servlet. Works with the Eclipse Visual Editor.
RIB | www.alphaworks.ibm.com/tech/rib - Reflexive User Interface Builder -- Another IBM approach using XML to represent a Swing / SWT user interface.
xmlgui | xmlgui.tigris.org - Interesting, but little documentation. Has editor. Defines additional useful widgets. Has been used in real project so probably works ok. Not appropriate for simplifying student programs. Open source.
SpeedGJ | www.wsoftware.de/SpeedJG - I'm looking for free student tools. Might be good, but at $70 I'm not going to check it out.
xWidglets | xwidglets.secretgate.com - GUI editor produces XML UI representation. Free download includes editor, gui engine, documentation. The web site is in French, but at least some of the screenshots show English menus. It's not clear how this is used as an interface to a Java application (my interest), but an example is given using JavaScript. I haven't tried it.
FormBuilder | The SwingEmpire FormBuilder GUI editor builds on the excellent JGoodies layouts, but it doesn't seem mature yet. Last updated 2004?
Java-XML-GuiBuilder | sourceforge.net/projects/jxmlguibuilder/ - GUI builder from XML. Open soure. Last update 2003.
XUI [1] | xui.sourceforge.net - Open source. Seems to be actively worked on. Doesn't appear to make small programs simpler. This is not the same as the XUI project listed below.
XMLTalk | sourceforge.net/projects/xmltalk - Target is handhelds. Open source.
KoalaGML | koalagml.sourceforge.net - Open source. Inactive?
Ultrid | www.ultrid.com - There is active development on this project. My first look at it had left a lot of Java details unexplained, but there's a lot more there now. Supports many layouts including table layout, splash screens, wizards, localization, and much more. Also strong support for various scripting languages. Worth a look. It appears to be free (beta 0.7.5), but without source.

There are related efforts, such as

Spring Rich Client | See Spring Rich Client
XAML | Microsoft's new XAML technology can be used to specify GUI (and much more) design in XML, and the tags directly map into C# classes and other MS languages. Take a look at this MSDN article - msdn.microsoft.com/msdnmag/issues/04/01/Avalon.
XUL | www.xulplanet.com/ - XUL is a spinoff of the Mozilla browser user interface project that has inspired many similar projects. This is somewhat of an umbrella organization for XML interfaces.
XForms | www.w3.org/TR/xforms may define sufficiently enhanced XML forms that can be used for program interfaces, but ...
BML | Bean Markup Language www.alphaworks.ibm.com/tech/bml/
JEasy | www.jeasy.de - $49
JBeaver | www.ratundtat.com - No longer available?
text2gui | www.tacosoftware.com/products/text2gui Uses resource bundles to store the GUI description in text. Can easily internationalize. Looks interesting. Not free.

### GUI Editors

jvider | www.jvider.com - $69. Last update 2004?
JFormDesigner | www.jformdesigner.com - 129 Euros. Has some very nice features.
JGB | Java GUI Builder jgb.sourceforge.net - Open source. Inactive?
Eclipse/VEP | www.eclipse.org/vep/WebContent/main.php - Eclipse Visual Editor Project plugin
Jigloo | www.cloudgarden.com/jigloo - SWT/Swing GUI Builder for Eclipse and WebSphere - Free for non-commercial use
FormLayoutMaker | sourceforge.net/projects/formlayoutmaker/ - WYSIWYG tool that enables you to easily build Java Swing layouts using the JGoodies FormLayout layout manager. Open source.
Abeille | abeille.dev.java.net/ - "Abeille Forms Designer is a GUI builder for Java applications. Developers and designers can create complex, professional forms in minutes. Designers can drag and drop components onto a WYSIWYG editor. Full support for undo/redo and copy/paste is provided. Components can be easily customized by adding images or modifying their properties. Advanced fill effects are supported such as textures and gradients."
Java Object Face | sourceforge.net/projects/jof/ - "JOF provide a way for displaying and populating java objects. JOF automate the creation of GUI forms and it’s able to produce AWT/Swing/JSP interfaces, just by passing java bean or XML to it.JOF is an Object-to-GUI solution!"
Atris | sourceforge.net/projects/atrisframework - Open source.
Foam | www.computersinmotion.com $150, 15-day free trial, but it's free to students and educators. Uses it's own layout manager. Take a look at the video. Separates the interface from "model". Apparently cross platform. Looks interesting, but website doesn't have much documentation.
Qt Designer | www.trolltech.com/products/qt/designer.html can produce a .ui file that can be run thru UICompiler (uic.sourceforge.net). I've tried this combination, and was unable to get it working without errors, perhaps because on Windows the only free version of Qt Designer (2.3) is old and didn't play well with UICompiler.
RADi | www.muntjak.de/hans/java/radi/index.html - Free for non-commercial use. RADi is an easy-to-use, though powerful, Java GUI builder and JavaBeansTM container. It is intuitive to use, supports drag and drop and you don't have to care about layout managers. Though you can create layouts of any complexity, RADi provides tools to master this complexity. RADi comes with a royalty-free runtime library which processes your layout definition files, creates the GUI and executes listeners, event and property handlers.

### Alternatives to Swing

Altho Swing (or the older AWT) is the standard for a Java GUI, there are alternatives. These alternatives exist because some are smaller and/or faster than the very general, but large and somewhat sluggish Swing library.

SWT | Standard Widget Toolkit, www.eclipse.org. This free GUI library from IBM provides an interface to the native system GUI (currently Windows and GNOME). The advantages are a more responsive user experience, and the Eclipse GUI editor for uses SWT, not Swing. The disadvantages are a different API so your programs can't simply be changed from Swing to SWT, and it isn't as portable, at least until versions are available for more systems. It's possible to compile completely native (no virtual machine!) programs for Linux.
SwingWT | swingwt.sourceforge.net. This free GUI implementation provides a Swing compatible API, but uses SWT for the implementation. Because it's compatible with Swing, it's easy to try this out.
BambooKit | www.bambookit.com. Light-weight XML-based GUI good for small devices.
Zaval | www.zaval.org. Another light-weight GUI.

### See also

- Automatically generated UI code: good, bad, or ugly? for a discussion of GUI generators.