FiruzzZ
(jose luis romero)
August 29, 2017, 3:09pm
1
I recently discovered a 2nd way to give format to data, instead of a Converter use a Renderer but this second does not seem to work.
this works:
.getColumn(3).setConverter(new StringToDateConverter() {
@Override
protected DateFormat getFormat(Locale locale) {
return new SimpleDateFormat("HH:mm");
}
});
this doesn’t: it showing in the cell the String “HH:mm” instead the Date formatted
getColumn(3).setRenderer(new DateRenderer("HH:mm"));
What am I doing wrong?
PD: forum bug > the button to format “code” in the topic doesn’t work
mcollovati
(Marco Collovati)
August 29, 2017, 7:52pm
2
Hi,
as stated in
DateRenderer javadocs
the string you pass to the constructor is a “format string” as defined in
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax
, not a date format pattern.
In your case you can use
%tR
as format string (see
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#dt
)
getColumn(3).setRenderer(new DateRenderer("%tR"));
HTH
Marco
mdoctor
(Miguel Doctor)
August 2, 2018, 1:13pm
3
Hi,
If you want to keep using date format patterns instead of “format strings” as indicated by Marco, the only thing you need to do is passing a SimpleDateFormat object to your DateRender constructor.
String sPattern = "HH:mm";
getColumn(3).setRenderer(new DateRenderer(new SimpleDateFormat(sPattern)));
Hope it helps
Miguel