Frequently Asked Questions |
From JAXXWiki
Contents |
General questions
What is JAXX?
JAXX is a user-interface programming language for Java. JAXX source files compile into Java classes which (generally) extend Swing components. For instance, the following XML represents a simple dialog:
<JDialog title='Sign In'>
<Table>
<row>
<cell><JLabel text='Username:'/></cell>
<cell><JTextField id='username'/></cell>
</row>
<row>
<cell><JLabel text='Password:'/></cell>
<cell><JPasswordField id='password'/></cell>
</row>
<row>
<cell columns='2'>
<JPanel layout='{new GridLayout(1, 2, 6, 6)}'>
<JButton text='OK'/>
<JButton text='Cancel'/>
</JPanel>
</cell>
</row>
</Table>
</JDialog>
This code compiles into an ordinary Java class which extends JDialog. When the dialog is displayed, it looks like this:
Of course, this example is brain-dead and doesn't use any of JAXX's advanced features like scripting, data binding, or stylesheets. See the Examples page for more interesting example programs.
What does "JAXX" stand for?
It stands for "something that sounds vaguely Java and XML related and wasn't already trademarked". It's written in all caps for no better reason than because I think it looks better that way.
How is JAXX licensed?
JAXX is available under the BSD License. It is completely free for both commercial and non-commercial use, and you may modify it and distribute your modifications so long as the original license and copyright notices remain intact.
Tool support
Do any IDEs feature JAXX support?
Not natively, but modern IDEs are nothing if not flexible. Gregg Sporar has written a great article about configuring NetBeans for JAXX support. I'm told that Eclipse can be similarly configured.
Is there a visual builder for JAXX?
Not yet, but it's coming. I'm in the middle of writing a tool which will take an existing Swing user interface and "serialize" it to a JAXX file, which will go part of the way towards solving this problem. It should also (in the relatively near future) be possible to use Matisse, the form builder built into NetBeans, to build a JAXX user interface. A real, JAXX-specific visual builder will follow when time allows.
Tag support
Where is the list of JAXX's supported tags?
JAXX's tags are documented under List of JAXX tags. Of course, as any Java class can be used as a class tag, this list is necessarily partial and focuses on the Swing components.
How do I add support for additional tags?
First, make sure that's what you really intend to do -- unlike most of the competition, JAXX supports all Java classes, including any custom components you may have created, without any special effort. You can most likely work with whatever component you are trying to use simply by using it as a class tag. If you do in fact need to add additional tag support, the best way to do it is by creating a JAXX Service Provider Interface .jar file.
Usage
Help! I found a bug!
If you think you have found a bug in JAXX, first check the Known issues page. If it is a known bug, there may be a workaround posted. The community forums are also an excellent place to check for help -- Ethan usually responds to questions very quickly. If at all possible, try to post a complete JAXX file that demonstrates the problem.
I compiled a JAXX file, but when I try to run it Java throws a NoSuchMethodError: main exception
JAXX files are ordinary Java classes and, like most Java classes, do not normally have main() methods. If you want a particular class to have a main() method, the easiest way to do this is to have it extend <Application> (by using <Application> as the root tag in the JAXX file). <Application> is a subclass of <JFrame>, and jaxxc automatically generates a main() method for all classes that extend it. If you don't want to extend <Application>, you can easily add a main() method to any class using a <script> tag:
<script>
public static void main(String[] arg) {
new ThisClass().setVisible(true);
}
</script>
How do I handle internationalization in a JAXX file?
Essentially the same way you would in a Java file. Suppose you have a method Util.msg(String) which retrieves an internationalized message from a ResourceBundle. In Java, you might write something like this:
JButton cancel = new JButton(Util.msg("cancel"));
The JAXX equivalent is:
<JButton text='{Util.msg("cancel")}'/>
Scripting
How do I create an initializer that runs at startup?
The easiest way is to just put the code directly into a <script> tag:
<script>
System.out.println("component initialized");
</script>
In the compiled class file, bare Java statements like this will be invoked by the constructor.
I don't like JAXX's script files. Why not use Java files instead?
You can. Scripting in JAXX is completely optional. If you want to put all of your code into .java files and have them make calls into your JAXX components, with no scripting at all in the .jaxx file, you're welcome to do that. The drawback to this approach is that all event handling in the .jaxx file would have to be configured from outside, using Java code.
A better approach in many ways is to put "substantial" code in .java files, and then use quick one-line scripts (onActionPerformed="javaObject.submitButtonClicked()") to invoke them. This allows JAXX to perform the tedious work of configuring event handling, while still having all of the "real" code in ordinary .java files. The Calculator example uses this mechanism: the actual calculations are performed by a normal Java class, but scripted event handlers are used to make calls into the calculation engine.
Note that this decision is purely a matter of taste. As JAXX files are fully compiled, the code runs equally fast whether you put it in a JAXX file or a a Java file.
Other questions?
If you have a question not answered above, head over to the forums or send an email to Ethan at ethan@ethannicholas.com.


