Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Rep Power

    Default Custom alignment of SWT widgets inside Composite

    Hi Friends,

    I have create a Composite object as follows.

    Composite comp = new Composite(parent, SWT.NONE);
    GridLayout gl = new GridLayout();
    gl.numColumns = 2;
    gl.verticalSpacing = 15;
    gl.horizontalSpacing = 10;
    gl.marginWidth = 20;

    I want to create 4 rows with one label and one text box. It worked fine for me.
    Now in the last row I want to display a label, Text box and a Button.
    The 4 rows were created with code something similar to given below.

    // Create a label and text box for the host
    Label myLabel = new Label(comp, SWT.NONE);
    myLabel.setText("Info: ");
    myText = new Text(comp, SWT.BORDER);
    myText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    I tried by increasing numColumns of Grid Layout, which resulted in label of
    next row appearing in current row. Can anyone suggest the solution please ?


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

  3. #3
    Bill Ewing is offline Member
    Join Date
    Dec 2010
    Encinitas, CA
    Rep Power


    Try putting a composite in the fourth row. Then you can set its layout to grid layout with four columns.

    Another way is make every row have the same number of items. You can use borderless Labels with no text to do that. Hokey, but it'll work.

Similar Threads

  1. getting problem in disposing the widgets
    By thendral m in forum SWT / JFace
    Replies: 7
    Last Post: 01-12-2010, 09:37 AM
  2. How to create widgets on some event
    By sarbuland in forum Advanced Java
    Replies: 0
    Last Post: 02-06-2008, 09:08 PM
  3. How to create widgets dynamically
    By sarbuland in forum Advanced Java
    Replies: 0
    Last Post: 02-06-2008, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts