You can use the css property "white-space:pre" to achieve this
effect. Alternately you can also use an HTML instead of a Label and
have a <pre> element within. See an example for both methods below.
public void onModuleLoad() {
String content = "abc\ndef\nghi";
// use a pre element in native HTML
HTML html = new HTML("<pre>" + content + "</pre>");
RootPanel.get().add(html);
// set the white space property explicitely on a label
Label label = new Label(content);
DOM.setStyleAttribute(label.getElement(), "whiteSpace", "pre");
RootPanel.get().add(label);
// define a class with the white space property in a css file,
load the css file and apply to label
// .preFormatted {
// white-space: pre;
// }
Label styledLabel = new Label(content);
styledLabel.addStyleName("preFormatted");
RootPanel.get().add(styledLabel);
}
Hope this helps!
Aragos