Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting number of rows to be displayed for Multi line text in swt

I am using following for TextArea

ToolBar bar = new ToolBar(box,SWT.NONE);
ToolItem item = new ToolItem(bar, SWT.SEPARATOR);
Text text = new Text(bar, SWT.BORDER | SWT.MULTI);
item.setWidth(width);
item.setControl(text);

GridData data = new GridData();
data.verticalAlignment = SWT.CENTER;
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
text.setLayoutData(data);

I want to display a multi line text box, currently its accepting multi line text but showing only a single line at a time.

Any idea how to set the number of rows to be displayed ?

Thanks.

like image 388
nik7 Avatar asked Feb 06 '12 21:02

nik7


People also ask

How do I display text on multiple lines?

The correct way to do things is using things made for the things you need. If you want a line break (enter), use <br> ; If you want to define a paragraph, use <p> . Show activity on this post. According to this, the <br> element is used to insert a line break without starting a new paragraph.

What is a multi line text field?

A multline text input field stores a string as its value and a string as its text. Its value is always a valid string, while its text could be any string entered into its editor. Unlike a text input field, this field also supports newline characters entered in the editor.


1 Answers

You can also use Text.getLineHeight() to determine the height of a single line of text, you don't need a GC for that:

final Text text = new Text(container, SWT.BORDER | SWT.WRAP);
GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
gridData.heightHint = 5 * text.getLineHeight();
text.setLayoutData(gridData);
like image 135
devconsole Avatar answered Oct 24 '22 11:10

devconsole