Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » how to set a maximum width to a Text component ?
how to set a maximum width to a Text component ? [message #647893] Mon, 10 January 2011 05:28 Go to next message
Gary Long is currently offline Gary Long
Messages: 2
Registered: January 2011
Junior Member
Hi :)

I created a small GUI which contains a SashForm and, inside this sf, a
tree on the left side and a Text on the right side. I would like the
tree to be resizable and the Text to have a fixed width.

At the moment, when I write some text in the Text component and when it
comes to the Text's right border, the text does not return to the next
line...

Here is my current code :

public void createPartControl(Composite parent) {


/*
* Create the main view grid
*/
parent.setLayout(new GridLayout(1,true));
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

/*
* Create container grid for composition and comment controls
*/
Composite dataContainer = new Composite(parent, SWT.NONE);
dataContainer.setLayout(new GridLayout(4, false));
dataContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

/*
* Create controls for Composition part
*/
SashForm sf = new SashForm(dataContainer, SWT.HORIZONTAL);
gridData = new GridData();
gridData.horizontalSpan = 4;
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessVerticalSpace = true;
sf.setLayoutData(gridData);

compoTree = new Tree(sf, SWT.BORDER);
compoTree.setLinesVisible(true);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.horizontalSpan = 4;
compoTree.setLayoutData(gridData);
TreeItem item = new TreeItem(compoTree, SWT.NONE);
item.setText("Composition");
compoTree.update();

commentArea = new Text(sf, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL );
gridData = new GridData();
gridData.widthHint = 150;
commentArea.setLayoutData(gridData);
commentArea.setText("You can enter comments here...");

...

}

I tried to set the gridData widthHint for the Text component
(commentArea) but it didn't change its behaviour.

I don't know what to try next =(

Regards,
Gary Long
Re: how to set a maximum width to a Text component ? [message #647914 is a reply to message #647893] Mon, 10 January 2011 07:56 Go to previous messageGo to next message
Lakshmi Shanmugam
Messages: 274
Registered: July 2009
Location: India
Senior Member
Hi,

You cannot set a layout to the SashForm (note that SashForm.setLayout() is overridden).
SashForm automatically takes care of layout and size of its child controls based on the weights set for them. Please see SashForm.setWeights(). and example snippet to use it --> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet109 .java

Also, you should use the SWT.WRAP style if you want the text to wrap.
Text commentArea = new Text(form, SWT.MULTI | SWT.WRAP| SWT.BORDER | SWT.V_SCROLL );

HTH,
Lakshmi


Lakshmi P Shanmugam
Re: how to set a maximum width to a Text component ? [message #648131 is a reply to message #647914] Tue, 11 January 2011 06:17 Go to previous message
Gary Long is currently offline Gary Long
Messages: 2
Registered: January 2011
Junior Member
Hi :)

I used the SWT.WRAP as you said and, indeed, it solved the problem :)

Thank you for your help !

Regards,
Gary

Le 10/01/2011 13:56, Lakshmi Shanmugam a écrit :
> Hi,
>
> You cannot set a layout to the SashForm (note that SashForm.setLayout()
> is overridden).
> SashForm automatically takes care of layout and size of its child
> controls based on the weights set for them. Please see
> SashForm.setWeights(). and example snippet to use it
> --> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet109 .java
>
>
> Also, you should use the SWT.WRAP style if you want the text to wrap.
> Text commentArea = new Text(form, SWT.MULTI | SWT.WRAP| SWT.BORDER |
> SWT.V_SCROLL );
>
> HTH,
> Lakshmi
Previous Topic:Layout problem on windows 7.
Next Topic:Problems with scroll synchronization of 2 trees
Goto Forum:
  


Current Time: Thu Aug 21 02:35:06 EDT 2014

Powered by FUDForum. Page generated in 0.01949 seconds