Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to wrap text in a Label
How to wrap text in a Label [message #660342] Thu, 17 March 2011 23:03 Go to next message
Eclipse UserFriend
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 #660343 is a reply to message #660342] Thu, 17 March 2011 23:26 Go to previous messageGo to next message
Eclipse UserFriend
I should add that I am doing my development on OS X though the target OS for the users is Windows (and I haven't tested this code on Windows yet).

I've seen some cases where things related to widgets seem to work better on one OS versus another......
Re: How to wrap text in a Label [message #660413 is a reply to message #660343] Fri, 18 March 2011 07:06 Go to previous message
Eclipse UserFriend
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.
Previous Topic:Running Pentaho Data Integration on Puppy Lucid 5.2
Next Topic:Display.getDefault().syncExec(...) deadlock?
Goto Forum:
  


Current Time: Tue Sep 02 19:26:26 EDT 2025

Powered by FUDForum. Page generated in 0.08151 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top