The goal is to allow using XHTML like XML tags to do your swing layout.

Currently basic features are supported but more components and layout options are needed. Personally I seem to have little time these days for these things so its going slow..

With the current code you use XML like the following to create a layout like the picture below..

<?xml version="1.0" encoding="UTF-8" ?>
<layout>
  <table border='12' cellspacing='5'>
    <tr>
      <td align='left'>
        <JLABEL id='label1' text='Login'/>
      </td>
      <td colspan='2'>
        <JTEXTFIELD id='field1' size='20'/>
      </td>
    </tr>
    <tr>
      <td align='left'>
        <JLABEL id='label2' text='Password'/>
      </td>
      <td colspan='2'>
        <JTEXTFIELD id='field2' size='20'/>
      </td>
    </tr>
    <tr>
      <td/>
      <td align='center' weightx='1'>
        <JBUTTON id='ok' text='OK'/>
      </td>
      <td align='center' weightx='1'>
        <JBUTTON id='cancel' text='Cancel'/>
      </td>
    </tr>
  </table>
</layout>

This creates a layout that looks like this:


The code to create this is simply:
    JFrame frame = new JFrame();
    XMLLayout layout = new XMLLayout(getClass(), fileName);
    JComponent panel = layout.getMainComponent();
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
    
The filename is loaded with Class.getResourceAsStream() and is relative to the classfile of the class you give when constructing the layout object.

To access the components you can do something like this:
    JTextField loginField = (JTextField)layout.getComponent("field1");
    String text = loginField.getText();
    
When a component is given an "id" attribute this is used as the key to retrieve the component from the layout. This attribute is the only default attribute all the components have. The same "id" value is also set to the component as a name with the JComponent.setName() method. This helps you to find your components by their name if using something like Jemmy for testing.

I try to keep a good set of JUnit tests that also might be of some use as examples. They are in the CVS.