Hi,
Finaly I understood what was wrong: The setFormatter() method was protected
(silly me)!
I have to say that this swixml classes are almost over my understanding but I'm
learning too, that is only good thing.
We have to use the setFormatterFactory(). The actual Formatters are then set for
default, display, edit, and null states.
How do you suggest to set those classes in XUL?
Do you think that it can be given as expressed in MyEx.xml or is this way
inconsistent with your future plans.
With the following code I can register the FormatterFactory attribute, but it
does not do any formatting yet because that part is still missing.
//Jarmo
START FormatterFactoryConverter.java -----------------------------------
package org.swixml.converters;
import org.jdom.Attribute;
import org.swixml.Converter;
import javax.swing.JFormattedTextField;
import javax.swing.text.DefaultFormatterFactory;
public class FormatterFactoryConverter implements Converter {
public Object convert(Class type, Attribute attr) {
// silly test, should be expanded with default,display,edit and null
AbstractFormatters
return new DefaultFormatterFactory();
}
public Class convertsTo() {
return JFormattedTextField.AbstractFormatterFactory.class;
}
}
END FormatterFactoryConverter.java -----------------------------------
START MyEx.java -----------------------------------
import org.swixml.ConverterLibrary;
import org.swixml.SwingEngine;
import org.swixml.converters.FormatterFactoryConverter;
public class MyEx extends SwingEngine {
private MyEx() {
Class classFormatter =
javax.swing.JFormattedTextField.AbstractFormatterFactory.class;
Class classControl = javax.swing.JFormattedTextField.class;
ConverterLibrary.getInstance().register(classFormatter, new
FormatterFactoryConverter());
this.taglib.registerTag("formattedtextfield", classControl);
try {
render("MyEx.xml").setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new MyEx();
}
}
END MyEx.java -----------------------------------
START MyEx.xml -----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<frame>
<formattedtextfield FormatterFactory="myDefaultFormatter,myDisplayFormatter
, myEditFormatter, myNullFormatter" />
</frame>
END MyEx.xml -----------------------------------