edit this page - page history - about editing

Extending java.text.MessageFormat

Java

I had a problem where I was required to use java.text.MessageFormat, but this formatter doesn't allow for formatting boolean values. However, it is possible to add new formatters to an existing MessageFormat instance, if they are instances of java.text.ChoiceFormat:

String actualPattern = "{0}";
MessageFormat mf = new MessageFormat(actualPattern);
mf.setFormat(0, new MyFormatter());
// proceed with formatting

You can see my custom formatter, which returns "/" on true, "" on false, directly on SVN.
Categories: Java | Technology | Code Samples
edit this page - what links to here? - page history - top
Last edited by jevon jevon 121 months ago