Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Since the SwingXBuilder subclasses the SwingBuilder, the same operations apply to the SwingXBuilder.

New Features in SwingXBuilder

Shortcutting/Aliasing attribute names

This has actually been around for a while but I only spoke about it to my mentors and not you guys.
Sometimes attribute names are a bit long to type. In this example pulled from one of the unit tests, we can see how to add an alias for any property on a component. During builder parsing, the names are changed to their explicit forms.

Code Block
builder.addShortcut(CheckerboardPainter.class,"squareSize", "size")
builder.addShortcut(CheckerboardPainter.class,"lightPaint", "light")
builder.addShortcut(CheckerboardPainter.class,"darkPaint", "dark")
def cp = builder.checkerboardPainter(size:40.0d, light:Color.WHITE, dark:Color.RED)

Before you ask, I did play around a bit with the idea of aliasing the component names but that was a bit cumbersome.

NOTE: Be careful when aliasing properties, making sure the alias doesn't already exist as a property name. For example, foreground and foregroundPainter exist for some components.