ListGridField nameField = new ListGridField("countryName", "Country");
ListGridField capitalField = new ListGridField("capital", "Capital");
ListGridField populationField = new ListGridField("population", "Population");
populationField.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
if (value == null) return null;
try {
NumberFormat nf = NumberFormat.getFormat("0,000");
return nf.format(((Number) value).longValue());
} catch (Exception e) {
return value.toString();
}
}
});
ListGridField areaField = new ListGridField("area", "Area (km²)");
areaField.setType(ListGridFieldType.INTEGER);
areaField.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
if (value == null) return null;
String val = null;
try {
NumberFormat nf = NumberFormat.getFormat("0,000");
val = nf.format(((Number) value).longValue());
} catch (Exception e) {
return value.toString();
}
return val + "km²";
}
});
ListGridField gdpField = new ListGridField("gdp", "GDP");
gdpField.setAlign(Alignment.RIGHT);
gdpField.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
if (value == null) return null;
try {
NumberFormat nf = NumberFormat.getFormat("0,000");
return "$" + nf.format(((Number) value).longValue());