Data type |
From JAXXWiki
In JAXX, a data type is the type associated with a class tag attribute. As XML attributes are string values, a supported data type is one that JAXX can convert from a string representation (in the JAXX file) to an instance of the appropriate type.
Contents |
Supported data types
Support for these data types is built into JAXX.
| Destination type | Possible string values |
|---|---|
| boolean / Boolean | Either "true" or "false" |
| char / Character | Any string of length 1 |
| short / Short | Any string accepted by Short.parseShort() |
| int / Integer | Any string accepted by Integer.parseInt() or the name of an enumeration constant, for enumerated properties |
| long / Long | Any string accepted by Long.parseLong() |
| float / Float | Any string accepted by Float.parseFloat() |
| double / Double | Any string accepted by Double.parseDouble() |
| java.lang.String | Any string |
| java.awt.Color | HTML-type colors of the form #rrggbb where rr, gg, and bb are two-digit hexadecimal numbers, or the name of a constant in the class java.awt.Color, such as white or blue |
| java.awt.Insets | Four comma-separated integers, or (as shorthand for four equal numbers) a single integer |
| javax.swing.KeyStroke | Any string accepted by KeyStroke.getKeyStroke() |
Enumerations
Many properties in Swing are int values that are enumerated, that is that they accept only a predefined set of constant values. Such int-typed enumerations may (in addition to raw int values) be assigned the case-insensitive name of one of the possible enumeration constants. For instance, JLabel's horizontalAlignment property, which in ordinary Java code might be assigned the value SwingConstants.RIGHT, would be assigned as follows:
<JLabel text='Right-aligned' horizontalAlignment='right'/>
Enumerated int properties must be properly described by the class' BeanInfo for this to be possible. This is the case for most or all built-in Swing properties, but may not be the case for custom properties you have added yourself.
Unsupported data types
If you wish to assign a value to a property with an unsupported data type, you will need to use a data binding expression (Java code in curly braces). This enables attributes of any type to be assigned, and because it is so easy to do so, JAXX does not need to provide direct support for complex data types such as Font and Border. Java code is already perfectly suitable for representing those types, with the additional benefit that you do not have to learn new ways to represent them as strings.
Example
This example shows various types of properties:
<JLabel text='Example Label:'
background='red'
opaque='true'
displayedMnemonic='E'
horizontalTextPosition='left'
border='{BorderFactory.createEtchedBorder()}'
labelFor='{textField}'/>
<JTextField id='textField'/>
Adding new data types
The JAXX Service Provider Interface allows you to easily add support for new data types, simply by including a specially-constructed .jar file in the class path.

