How to wrap text in a Label [message #660342] |
Thu, 17 March 2011 23:03  |
Eclipse User |
|
|
|
I am trying to put a Label on a Composite in a JFace PreferencePage. I'd like to make it so that the label wraps the text itself rather than me putting in newline characters. I've searched for how to do and it appears you're supposed to be able to construct the label with the SWT.WRAP bit but this isn't working for me. Here is what I am doing:
Composite myParent = new Composite( parent, SWT.NONE ) ;
GridLayout gridLayout = new GridLayout() ;
gridLayout.numColumns = 1;
myParent.setLayout( gridLayout ) ;
Label instructionsLbl = new Label( myParent, SWT.WRAP ) ;
String instructionsStr = "The following settings control the behavior " +
"of the editor . Selections here " +
"will alter the behavior of the editor after you" +
"save these changes by clicking \'Apply\'.";
instructionsLbl.setText( instructionsStr );
GridData gridData = new GridData( SWT.WRAP ) ;
gridData.grabExcessHorizontalSpace = true ;
gridData.horizontalAlignment = SWT.FILL;
instructionsLbl.setLayoutData( gridData ) ;
Many of the code examples I've seen are pure SWT examples whereas this is JFace/SWT inside of an RCP app. Does that have anything to do with it, or is there something more fundamentally wrong with what I am doing?
Thanks,
Jon
|
|
|
|
Re: How to wrap text in a Label [message #660413 is a reply to message #660343] |
Fri, 18 March 2011 07:06  |
Eclipse User |
|
|
|
Well, the above code will work for a simple SWT shell. I have slightly changed your code so that your code will make the label wrap in the preferences
------------------------------------
Composite myParent = new Composite( arg0, SWT.NONE ) ;
GridLayout gridLayout = new GridLayout(1,false) ;
myParent.setLayout( gridLayout ) ;
GridData layoutData = new GridData(GridData.FILL_BOTH);
layoutData.horizontalSpan = 1;
myParent.setLayoutData(layoutData);
Label instructionsLbl = new Label( myParent, SWT.WRAP ) ;
String instructionsStr = "The following settings control the behavior " +
"of the editor . Selections here " +
"will alter the behavior of the editor after you" +
"save these changes by clicking \'Apply\'.";
instructionsLbl.setText( instructionsStr );
GridData gridData = new GridData( GridData.FILL_HORIZONTAL ) ;
gridData.grabExcessHorizontalSpace = true ;
gridData.horizontalAlignment = SWT.FILL;
gridData.widthHint = 200;
gridData.horizontalSpan = 2;
instructionsLbl.setLayoutData( gridData ) ;
return myParent;
------------------------------------
Hope this helps.
Regards, Praveen.
|
|
|
Powered by
FUDForum. Page generated in 0.03162 seconds