Reputation: 738
I want to make a label that will contain a few strings, each one in a new line.
For example: how to make label.setText(srt1/nstr2);
look like this :
string1
string2
I've tried to use /n
but it doesn't work. so, what should I do it?
Upvotes: 2
Views: 3950
Reputation: 528
This worked for me. See if this helps.
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class MultiLineLabel {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Label l = new Label(shell, SWT.WRAP);
l.setText("First Line\nSecond Line");
l.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Upvotes: 7